guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

08/08: scripts: git: log: Add '--grep'.


From: guix-commits
Subject: 08/08: scripts: git: log: Add '--grep'.
Date: Mon, 4 Jul 2022 07:07:57 -0400 (EDT)

rekado pushed a commit to branch wip-guix-log
in repository guix.

commit c215307e0c8d3b20b8377ef9beeccbc81894db97
Author: Magali Lemes <magalilemes00@gmail.com>
AuthorDate: Tue Jan 19 19:21:48 2021 -0300

    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 @@
                   (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 @@ Show Guix commit logs.\n"))
   (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=<string>  show log according to string"))
   (newline)
@@ -195,11 +200,14 @@ id instead of the 40-character one."
           (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 @@ id instead of the 40-character one."
   (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)))))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]