all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 53195b423c728afdda3f935604e7a865a16c4b84 6464 bytes (raw)
name: guix/scripts/describe.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guix scripts describe)
  #:use-module ((guix ui) #:hide (display-profile-content))
  #:use-module (guix scripts)
  #:use-module (guix describe)
  #:use-module (guix profiles)
  #:use-module ((guix scripts pull) #:select (display-profile-content))
  #:use-module (git)
  #:use-module (json)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-37)
  #:use-module (ice-9 match)
  #:autoload   (ice-9 pretty-print) (pretty-print)
  #:export (guix-describe))

\f
;;;
;;; Command-line options.
;;;

(define %options
  ;; Specifications of the command-line options.
  (list (option '(#\f "format") #t #f
                (lambda (opt name arg result)
                  (unless (member arg '("human" "channels" "json"))
                    (leave (G_ "~a: unsupported output format~%") arg))
                  (alist-cons 'format (string->symbol arg) result)))
        (option '(#\h "help") #f #f
                (lambda args
                  (show-help)
                  (exit 0)))
        (option '(#\V "version") #f #f
                (lambda args
                  (show-version-and-exit "guix describe")))))

(define %default-options
  ;; Alist of default option values.
  '((format . human)))

(define (show-help)
  (display (G_ "Usage: guix describe [OPTION]...
Display information about the channels currently in use.\n"))
  (display (G_ "
  -f, --format=FORMAT    display information in the given FORMAT"))
  (newline)
  (display (G_ "
  -h, --help             display this help and exit"))
  (display (G_ "
  -V, --version          display version information and exit"))
  (newline)
  (show-bug-report-information))

(define (display-package-search-path fmt)
  "Display GUIX_PACKAGE_PATH, if it is set, according to FMT."
  (match (getenv "GUIX_PACKAGE_PATH")
    (#f #t)
    (string
     (match fmt
       ('human
        (format #t "~%GUIX_PACKAGE_PATH=\"~a\"~%" string))
       ('channels
        (format #t (G_ "~%;; warning: GUIX_PACKAGE_PATH=\"~a\"~%")
                string))))))

(define (display-checkout-info fmt)
  "Display information about the current checkout according to FMT, a symbol
denoting the requested format.  Exit if the current directory does not lie
within a Git checkout."
  (let* ((program    (car (command-line)))
         (directory  (catch 'git-error
                       (lambda ()
                         (repository-discover (dirname program)))
                       (lambda (key err)
                         (leave (G_ "failed to determine origin~%")))))
         (repository (repository-open directory))
         (head       (repository-head repository))
         (commit     (oid->string (reference-target head))))
    (match fmt
      ('human
       (format #t (G_ "Git checkout:~%"))
       (format #t (G_ "  repository: ~a~%") (dirname directory))
       (format #t (G_ "  branch: ~a~%") (reference-shorthand head))
       (format #t (G_ "  commit: ~a~%") commit))
      ('channels
       (pretty-print `(list (channel
                             (name 'guix)
                             (url ,(dirname directory))
                             (commit ,commit)))))
      ('json
       (display (scm->json-string `((name . guix)
                                    (url . ,(dirname directory))
                                    (commit . ,commit))))
       (newline)))
    (display-package-search-path fmt)))

(define (display-profile-info profile fmt)
  "Display information about PROFILE, a profile as created by (guix channels),
in the format specified by FMT."
  (define number
    (generation-number profile))

  (define (channels format)
    (map (lambda (entry)
           (match (assq 'source (manifest-entry-properties entry))
             (('source ('repository ('version 0)
                                    ('url url)
                                    ('branch branch)
                                    ('commit commit)
                                    _ ...))
              (case format
                ((scm)
                 `(channel (name ',(string->symbol
                                    (manifest-entry-name entry)))
                           (url ,url)
                           (commit ,commit)))
                ((json)
                 `((name . ,(string->symbol
                             (manifest-entry-name entry)))
                   (url . ,url)
                   (commit . ,commit)))))

             ;; Pre-0.15.0 Guix does not provide that information,
             ;; so there's not much we can do in that case.
             (_ '???)))

         ;; Show most recently installed packages last.
         (reverse
          (manifest-entries
           (profile-manifest
            (if (zero? number)
                profile
                (generation-file-name profile number)))))))

  (match fmt
    ('human
     (display-profile-content profile number))
    ('channels
     (pretty-print
      `(list ,@(channels 'scm))))
    ('json
     (display (scm->json-string (channels 'json)))
     (newline)))
  (display-package-search-path fmt))

\f
;;;
;;; Entry point.
;;;

(define (guix-describe . args)
  (let* ((opts   (args-fold* args %options
                             (lambda (opt name arg result)
                               (leave (G_ "~A: unrecognized option~%")
                                      name))
                             cons
                             %default-options))
         (format (assq-ref opts 'format)))
    (with-error-handling
      (match (current-profile)
        (#f
         (display-checkout-info format))
        (profile
         (display-profile-info (canonicalize-profile profile) format))))))

debug log:

solving 53195b423 ...
found 53195b423 in https://yhetil.org/guix/20181121070051.12041-1-go.wigust@gmail.com/
found d3203e992 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 d3203e99241365b226293ca2700099df8fd4b263	guix/scripts/describe.scm

applying [1/1] https://yhetil.org/guix/20181121070051.12041-1-go.wigust@gmail.com/
diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index d3203e992..53195b423 100644

Checking patch guix/scripts/describe.scm...
Applied patch guix/scripts/describe.scm cleanly.

index at:
100644 53195b423c728afdda3f935604e7a865a16c4b84	guix/scripts/describe.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.