unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 36644@debbugs.gnu.org
Subject: bug#36644: Git log search
Date: Sun, 14 Jul 2019 01:27:15 +0300	[thread overview]
Message-ID: <874l3p4lks.fsf@mail.linkov.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 163 bytes --]

It would be very useful to have the command to grep git logs,
for instance, to search commits by bug numbers in format "bug#36789"
and many other such use cases:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-log-search.patch --]
[-- Type: text/x-diff, Size: 2569 bytes --]

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index eb6d6d331f..d39af516a9 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -337,6 +337,10 @@
 ;;   Insert in BUFFER the revision log for the changes that will be
 ;;   received when performing a pull operation from REMOTE-LOCATION.
 ;;
+;; - log-search (pattern)
+;;
+;;   Search for PATTERN in the revision log.
+;;
 ;; - log-view-mode ()
 ;;
 ;;   Mode to use for the output of print-log.  This defaults to
@@ -2526,6 +2530,16 @@ vc-log-outgoing
     (vc-incoming-outgoing-internal backend (or remote-location "")
                                    "*vc-outgoing*" 'log-outgoing)))
 
+;;;###autoload
+(defun vc-log-search (pattern)
+  "Search a log of changes for PATTERN."
+  (interactive (list (read-regexp "Log search pattern: ")))
+  (let ((backend (vc-deduce-backend)))
+    (unless backend
+      (error "Buffer is not version controlled"))
+    (vc-incoming-outgoing-internal backend pattern
+                                   "*vc-search*" 'log-search)))
+
 ;;;###autoload
 (defun vc-log-mergebase (_files rev1 rev2)
   "Show a log of changes between the merge base of REV1 and REV2 revisions.
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 8b82856332..d1d6a7408e 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1073,6 +1075,13 @@ vc-git-log-incoming
 			"@{upstream}"
 		      remote-location))))
 
+(defun vc-git-log-search (buffer pattern)
+  (vc-setup-buffer buffer)
+  (vc-git-command
+   buffer 'async nil
+   "log"
+   "--no-color" "-i" (format "--grep=%s" pattern)))
+
 (defun vc-git-mergebase (rev1 &optional rev2)
   (unless rev2 (setq rev2 "HEAD"))
   (string-trim-right (vc-git--run-command-string nil "merge-base" rev1 rev2)))
@@ -1089,7 +1100,7 @@ vc-git-log-view-mode
   (set (make-local-variable 'log-view-file-re) regexp-unmatchable)
   (set (make-local-variable 'log-view-per-file-logs) nil)
   (set (make-local-variable 'log-view-message-re)
-       (if (not (eq vc-log-view-type 'long))
+       (if (not (memq vc-log-view-type '(long log-search)))
 	   (cadr vc-git-root-log-format)
 	 "^commit *\\([0-9a-z]+\\)"))
   ;; Allow expanding short log entries.
@@ -1098,7 +1109,7 @@ vc-git-log-view-mode
     (set (make-local-variable 'log-view-expanded-log-entry-function)
 	 'vc-git-expanded-log-entry))
   (set (make-local-variable 'log-view-font-lock-keywords)
-       (if (not (eq vc-log-view-type 'long))
+       (if (not (memq vc-log-view-type '(long log-search)))
 	   (list (cons (nth 1 vc-git-root-log-format)
 		       (nth 2 vc-git-root-log-format)))
 	 (append

             reply	other threads:[~2019-07-13 22:27 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-13 22:27 Juri Linkov [this message]
2019-07-15 15:05 ` bug#36644: Git log search Dmitry Gutov
2019-07-15 22:27   ` Juri Linkov
2019-07-16 14:25     ` Dmitry Gutov
2019-07-16 14:44       ` Andreas Schwab
2019-07-16 15:08       ` Robert Pluim
2019-07-16 20:20         ` Juri Linkov
2019-07-16 22:31           ` Noam Postavsky
2019-07-18 22:35             ` Juri Linkov
2019-07-24 14:57             ` Dmitry Gutov
2019-07-16 20:15       ` Juri Linkov
2019-07-18 15:01         ` Dmitry Gutov
2019-07-18 15:12           ` Robert Pluim
2019-07-18 18:02             ` Dmitry Gutov
2019-07-18 18:11               ` Robert Pluim
2019-07-18 22:32               ` Juri Linkov
2019-07-24 15:10                 ` Dmitry Gutov
2019-07-24 15:46                   ` Robert Pluim
2019-07-24 15:53                     ` Dmitry Gutov
2019-07-24 16:13                       ` Eli Zaretskii
2019-07-25 12:36                         ` Dmitry Gutov
2019-07-25 13:08                           ` Eli Zaretskii
2019-07-25 13:20                             ` Dmitry Gutov
2019-07-25 13:37                             ` Robert Pluim
2019-07-25 19:00                             ` Juri Linkov
2019-07-25 18:55                           ` Juri Linkov
2019-07-25 21:26                             ` Dmitry Gutov
2019-07-25 21:38                               ` Juri Linkov
2019-07-24 16:13                       ` Robert Pluim
2019-07-24 17:04                         ` Eli Zaretskii
2019-07-24 23:22                           ` Juri Linkov
2019-07-25 12:44                             ` Dmitry Gutov
2019-07-25 18:50                               ` Juri Linkov
2019-07-25 19:19                                 ` Dmitry Gutov
2019-07-29 22:38                             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874l3p4lks.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=36644@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).