From c215307e0c8d3b20b8377ef9beeccbc81894db97 Mon Sep 17 00:00:00 2001 From: Magali Lemes Date: Tue, 19 Jan 2021 19:21:48 -0300 Subject: scripts: git: log: Add '--grep'. * guix/scripts/git/log.scm (show-help, %options): Add '--grep'. * Makefile.am (MODULES): Add 'guix/scripts/git/log.scm'. --- Makefile.am | 1 + guix/scripts/git/log.scm | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index 377cac03f7..8ce51c65a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -341,6 +341,7 @@ MODULES = \ guix/scripts/size.scm \ guix/scripts/git.scm \ guix/scripts/git/authenticate.scm \ + guix/scripts/git/log.scm \ guix/scripts/graph.scm \ guix/scripts/weather.scm \ guix/scripts/container.scm \ diff --git a/guix/scripts/git/log.scm b/guix/scripts/git/log.scm index afcf28b285..c07f3f4eb3 100644 --- a/guix/scripts/git/log.scm +++ b/guix/scripts/git/log.scm @@ -58,6 +58,9 @@ (define %options (unless (member arg %formats) (leave (G_ "~a: invalid format~%") arg)) (alist-cons 'format (string->symbol arg) result))) + (option '("grep") #t #f + (lambda (opt name arg result) + (alist-cons 'grep arg result))) (option '("oneline") #f #f (lambda (opt name arg result) (alist-cons 'oneline? #t result))) @@ -86,7 +89,9 @@ (define (show-help) (display (G_ " --format=FORMAT show log according to FORMAT")) (display (G_ " - --oneline show short hash and summary of five first commits")) + --grep=REGEXP show commits whose message matches REGEXP")) + (display (G_ " + --oneline show short hash and summary of commits")) (display (G_ " --pretty= show log according to string")) (newline) @@ -195,11 +200,14 @@ (define channels (channel-list '())) (let* ((channel-path (url-cache-directory (channel-url channel))) (repository (repository-open channel-path)) (latest-commit - (commit-lookup repository (object-id (revparse-single repository "origin/master"))))) + (commit-lookup repository + (object-id + (revparse-single + repository "origin/master"))))) (begin (hashq-set! %channels-repositories channel-path repository) (append (set->list (commit-closure latest-commit)) - commit-list)))) '() channels)) + commit-list)))) '() channels)) (define (guix-git-log . args) (define options @@ -208,19 +216,31 @@ (define options (let ((channel-cache (assoc-ref options 'channel-cache-path)) (oneline? (assoc-ref options 'oneline?)) (format-type (assoc-ref options 'format)) - (pretty-string (assoc-ref options 'pretty))) + (pretty-string (assoc-ref options 'pretty)) + (regexp (assoc-ref options 'grep))) (with-error-handling (cond (channel-cache (show-channel-cache-path channel-cache)) (oneline? - (for-each (lambda (commit-list) - (show-commit commit-list 'oneline #t)) - (get-commits))) + (leave-on-EPIPE + (for-each (lambda (commit) + (when (or (not regexp) + (string-match regexp (commit-message commit))) + (show-commit commit 'oneline #t))) + (get-commits)))) (format-type - (for-each (lambda (commit-list) - (show-commit commit-list format-type #f)) - (get-commits))) + (leave-on-EPIPE + (for-each (lambda (commit) + (when (or (not regexp) + (string-match regexp (commit-message commit))) + (show-commit commit format-type #f))) + (get-commits)))) (pretty-string (let ((pretty-show (cut pretty-show-commit pretty-string <>))) - (for-each pretty-show (get-commits)))))))) + (leave-on-EPIPE + (for-each (lambda (commit) + (when (or (not regexp) + (string-match regexp (commit-message commit))) + (pretty-show commit))) + (get-commits))))))))) -- cgit v1.2.3