diff options
| author | Magali Lemes <magalilemes00@gmail.com> | 2021-01-15 18:29:19 -0300 |
|---|---|---|
| committer | Ricardo Wurmus <rekado@elephly.net> | 2022-07-04 10:34:52 +0200 |
| commit | 754157f50b380d1b6fcbceaa9be6c5bfa7ca5aed (patch) | |
| tree | 567a2fddee8df73eab704d26f6a8959129fc2a18 | |
| parent | b8270a11d609ef2bfa81eed913b44077e5a49a04 (diff) | |
scripts: git: log: Add docstring.
* guix/scripts/git/log.scm (%options, list-channels, information-placeholders,
replace-regex, procedure-list, pretty-show-commit, show-channel-cache-path,
show-commit, get-commits): Add docstring.
* guix/scripts/git/log.scm: (%options, show-help): Add '--version'.
| -rw-r--r-- | guix/scripts/git/log.scm | 141 |
1 files changed, 82 insertions, 59 deletions
diff --git a/guix/scripts/git/log.scm b/guix/scripts/git/log.scm index 02876c763f0..afcf28b2854 100644 --- a/guix/scripts/git/log.scm +++ b/guix/scripts/git/log.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2020 Magali Lemes <magalilemes00@gmail.com> | 2 | ;;; Copyright © 2020, 2021 Magali Lemes <magalilemes00@gmail.com> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -38,10 +38,14 @@ | |||
| 38 | '("oneline" "medium" "full")) | 38 | '("oneline" "medium" "full")) |
| 39 | 39 | ||
| 40 | (define %options | 40 | (define %options |
| 41 | ;; Specifications of the command-line options. | ||
| 41 | (list (option '(#\h "help") #f #f | 42 | (list (option '(#\h "help") #f #f |
| 42 | (lambda args | 43 | (lambda args |
| 43 | (show-help) | 44 | (show-help) |
| 44 | (exit 0))) | 45 | (exit 0))) |
| 46 | (option '(#\V "version") #f #f | ||
| 47 | (lambda args | ||
| 48 | (show-version-and-exit "guix git log"))) | ||
| 45 | 49 | ||
| 46 | (option '("channel-cache-path") #f #t | 50 | (option '("channel-cache-path") #f #t |
| 47 | (lambda (opt name arg result) | 51 | (lambda (opt name arg result) |
| @@ -65,6 +69,7 @@ | |||
| 65 | '()) | 69 | '()) |
| 66 | 70 | ||
| 67 | (define (list-channels) | 71 | (define (list-channels) |
| 72 | "List channels and their checkout path" | ||
| 68 | (define channels (channel-list '())) | 73 | (define channels (channel-list '())) |
| 69 | (for-each (lambda (channel) | 74 | (for-each (lambda (channel) |
| 70 | (format #t "~a~% ~a~%" | 75 | (format #t "~a~% ~a~%" |
| @@ -84,8 +89,11 @@ Show Guix commit logs.\n")) | |||
| 84 | --oneline show short hash and summary of five first commits")) | 89 | --oneline show short hash and summary of five first commits")) |
| 85 | (display (G_ " | 90 | (display (G_ " |
| 86 | --pretty=<string> show log according to string")) | 91 | --pretty=<string> show log according to string")) |
| 92 | (newline) | ||
| 87 | (display (G_ " | 93 | (display (G_ " |
| 88 | -h, --help display this help and exit")) | 94 | -h, --help display this help and exit")) |
| 95 | (display (G_ " | ||
| 96 | -V, --version display version information and exit")) | ||
| 89 | (newline) | 97 | (newline) |
| 90 | (show-bug-report-information)) | 98 | (show-bug-report-information)) |
| 91 | 99 | ||
| @@ -94,25 +102,35 @@ Show Guix commit logs.\n")) | |||
| 94 | 102 | ||
| 95 | (define placeholders-regex "%([Hhsb]|(an)|(cn))") | 103 | (define placeholders-regex "%([Hhsb]|(an)|(cn))") |
| 96 | 104 | ||
| 97 | (define information-placeholders `(("%b" . ,commit-body) | 105 | (define information-placeholders |
| 98 | ("%H" . ,(compose oid->string commit-id)) | 106 | ;; Alist of placeholders and their corresponding procedure. |
| 99 | ("%h" . ,commit-short-id) | 107 | `(("%b" . ,commit-body) |
| 100 | ("%s" . ,commit-summary) | 108 | ("%H" . ,(compose oid->string commit-id)) |
| 101 | ("%an" . ,(compose signature-name commit-author)))) | 109 | ("%h" . ,commit-short-id) |
| 110 | ("%s" . ,commit-summary) | ||
| 111 | ("%an" . ,(compose signature-name commit-author)))) | ||
| 102 | 112 | ||
| 103 | (define (replace-regex string) | 113 | (define (replace-regex string) |
| 114 | "Return a string replacing all information placeholders with ~a" | ||
| 104 | (regexp-substitute/global #f placeholders-regex string 'pre "~a" 'post)) | 115 | (regexp-substitute/global #f placeholders-regex string 'pre "~a" 'post)) |
| 105 | 116 | ||
| 106 | (define (procedure-list string) | 117 | (define (procedure-list string) |
| 118 | "Return a list of procedures according to the placeholders contained in | ||
| 119 | string, in the order they appear" | ||
| 107 | (let* ((placeholders-in-the-string | 120 | (let* ((placeholders-in-the-string |
| 108 | (map match:substring (list-matches placeholders-regex string)))) | 121 | (map match:substring (list-matches placeholders-regex string)))) |
| 109 | (map (lambda (commit) | 122 | (map (lambda (commit) |
| 110 | (assoc-ref information-placeholders commit)) placeholders-in-the-string))) | 123 | (assoc-ref information-placeholders commit)) |
| 124 | placeholders-in-the-string))) | ||
| 111 | 125 | ||
| 112 | (define (pretty-show-commit string commit) | 126 | (define (pretty-show-commit string commit) |
| 113 | (format #t "~?~%" (replace-regex string) (map (lambda (f) (f commit)) (procedure-list string)))) | 127 | "Display commit according to string" |
| 128 | (format #t "~?~%" (replace-regex string) (map | ||
| 129 | (lambda (f) (f commit)) | ||
| 130 | (procedure-list string)))) | ||
| 114 | 131 | ||
| 115 | (define (show-channel-cache-path channel) | 132 | (define (show-channel-cache-path channel) |
| 133 | "Display channel checkout path." | ||
| 116 | (define channels (channel-list '())) | 134 | (define channels (channel-list '())) |
| 117 | 135 | ||
| 118 | (let ((found-channel (find (lambda (element) | 136 | (let ((found-channel (find (lambda (element) |
| @@ -122,61 +140,66 @@ Show Guix commit logs.\n")) | |||
| 122 | (format #t "~a~%" (url-cache-directory (channel-url found-channel))) | 140 | (format #t "~a~%" (url-cache-directory (channel-url found-channel))) |
| 123 | (leave (G_ "~a: channel not found~%") (symbol->string channel))))) | 141 | (leave (G_ "~a: channel not found~%") (symbol->string channel))))) |
| 124 | 142 | ||
| 125 | ;; --oneline = show-commit 'oneline #t | ||
| 126 | (define (show-commit commit fmt abbrev-commit) | 143 | (define (show-commit commit fmt abbrev-commit) |
| 144 | "Display commit according to fmt. If abbrev-commit is #t, then show short hash | ||
| 145 | id instead of the 40-character one." | ||
| 127 | (match fmt | 146 | (match fmt |
| 128 | ('oneline | 147 | ('oneline |
| 129 | (format #t "~a ~a~%" | 148 | (format #t "~a ~a~%" |
| 130 | (if abbrev-commit | 149 | (if abbrev-commit |
| 131 | (commit-short-id commit) | 150 | (commit-short-id commit) |
| 132 | (oid->string (commit-id commit))) | 151 | (oid->string (commit-id commit))) |
| 133 | (commit-summary commit))) | 152 | (commit-summary commit))) |
| 134 | ('medium | 153 | ('medium |
| 135 | (let ((author (commit-author commit)) | 154 | (let ((author (commit-author commit)) |
| 136 | (merge-commit (if (> (commit-parentcount commit) 1) #t #f))) | 155 | (merge-commit (if (> (commit-parentcount commit) 1) #t #f))) |
| 137 | (format #t "commit ~a~[~%Merge:~]~{ ~a~}~%Author: ~a <~a>~%Date: ~a~%~%~a~%" | 156 | (format #t "commit ~a~[~%Merge:~]~{ ~a~}~%Author: ~a <~a>~%Date: ~a~%~%~a~%" |
| 138 | (if abbrev-commit | 157 | (if abbrev-commit |
| 139 | (commit-short-id commit) | 158 | (commit-short-id commit) |
| 140 | (oid->string (commit-id commit))) | 159 | (oid->string (commit-id commit))) |
| 141 | (if merge-commit 0 1) ;; show "Merge:" | 160 | (if merge-commit 0 1) ;; show "Merge:" |
| 142 | (if merge-commit (map commit-short-id (commit-parents commit)) '()) | 161 | (if merge-commit (map commit-short-id (commit-parents commit)) '()) |
| 143 | (signature-name author) | 162 | (signature-name author) |
| 144 | (signature-email author) | 163 | (signature-email author) |
| 145 | (date->string | 164 | (date->string |
| 146 | (time-utc->date | 165 | (time-utc->date |
| 147 | (make-time time-utc 0 | 166 | (make-time time-utc 0 |
| 148 | (time-time (signature-when author))) | 167 | (time-time (signature-when author))) |
| 149 | (* 60 (time-offset (signature-when author)))) | 168 | (* 60 (time-offset (signature-when author)))) |
| 150 | "~a ~b ~e ~H:~M:~S ~Y ~z") | 169 | "~a ~b ~e ~H:~M:~S ~Y ~z") |
| 151 | (commit-message commit)))) | 170 | (commit-message commit)))) |
| 152 | ('full | 171 | ('full |
| 153 | (let ((merge-commit (if (> (commit-parentcount commit) 1) #t #f)) | 172 | (let ((merge-commit (if (> (commit-parentcount commit) 1) #t #f)) |
| 154 | (author (commit-author commit)) | 173 | (author (commit-author commit)) |
| 155 | (committer (commit-committer commit))) | 174 | (committer (commit-committer commit))) |
| 156 | (format #t "commit ~a~[~%Merge:~]~{ ~a~}~%Author: ~a <~a>~%Commit: ~a <~a>~%~%~a~%" | 175 | (format #t "commit ~a~[~%Merge:~]~{ ~a~}~%Author: ~a <~a>~%Commit: ~a <~a>~%~%~a~%" |
| 157 | (if abbrev-commit | 176 | (if abbrev-commit |
| 158 | (commit-short-id commit) | 177 | (commit-short-id commit) |
| 159 | (oid->string (commit-id commit))) | 178 | (oid->string (commit-id commit))) |
| 160 | (if merge-commit 0 1) ;; show "Merge:" | 179 | (if merge-commit 0 1) ;; show "Merge:" |
| 161 | (if merge-commit (map commit-short-id (commit-parents commit)) '()) | 180 | (if merge-commit (map commit-short-id (commit-parents commit)) '()) |
| 162 | (signature-name author) | 181 | (signature-name author) |
| 163 | (signature-email author) | 182 | (signature-email author) |
| 164 | (signature-name committer) | 183 | (signature-name committer) |
| 165 | (signature-email committer) | 184 | (signature-email committer) |
| 166 | (commit-message commit)))))) | 185 | (commit-message commit)))))) |
| 167 | 186 | ||
| 168 | ;; returns a list with commits from all channels | 187 | (define %channels-repositories |
| 188 | (make-hash-table)) | ||
| 189 | |||
| 169 | (define (get-commits) | 190 | (define (get-commits) |
| 191 | "Return a list with commits from all channels." | ||
| 170 | (define channels (channel-list '())) | 192 | (define channels (channel-list '())) |
| 171 | 193 | ||
| 172 | (fold (lambda (channel commit-list) | 194 | (fold (lambda (channel commit-list) |
| 173 | (let* ((channel-path (url-cache-directory (channel-url channel))) | 195 | (let* ((channel-path (url-cache-directory (channel-url channel))) |
| 174 | (repository (repository-open channel-path)) | 196 | (repository (repository-open channel-path)) |
| 175 | (latest-commit | 197 | (latest-commit |
| 176 | (commit-lookup repository (reference-target | 198 | (commit-lookup repository (object-id (revparse-single repository "origin/master"))))) |
| 177 | (repository-head repository))))) | 199 | (begin |
| 178 | (append (set->list (commit-closure latest-commit)) | 200 | (hashq-set! %channels-repositories channel-path repository) |
| 179 | commit-list))) '() channels)) | 201 | (append (set->list (commit-closure latest-commit)) |
| 202 | commit-list)))) '() channels)) | ||
| 180 | 203 | ||
| 181 | (define (guix-git-log . args) | 204 | (define (guix-git-log . args) |
| 182 | (define options | 205 | (define options |
| @@ -193,11 +216,11 @@ Show Guix commit logs.\n")) | |||
| 193 | (oneline? | 216 | (oneline? |
| 194 | (for-each (lambda (commit-list) | 217 | (for-each (lambda (commit-list) |
| 195 | (show-commit commit-list 'oneline #t)) | 218 | (show-commit commit-list 'oneline #t)) |
| 196 | (take (get-commits) 5))) | 219 | (get-commits))) |
| 197 | (format-type | 220 | (format-type |
| 198 | (for-each (lambda (commit-list) | 221 | (for-each (lambda (commit-list) |
| 199 | (show-commit commit-list format-type #f)) | 222 | (show-commit commit-list format-type #f)) |
| 200 | (take (get-commits) 5))) | 223 | (get-commits))) |
| 201 | (pretty-string | 224 | (pretty-string |
| 202 | (let ((pretty-show (cut pretty-show-commit pretty-string <>))) | 225 | (let ((pretty-show (cut pretty-show-commit pretty-string <>))) |
| 203 | (for-each pretty-show (take (get-commits) 5)))))))) | 226 | (for-each pretty-show (get-commits)))))))) |
