Improve passing user switches to Git log commands (bug#59414)

* lisp/vc/vc-git.el (vc-git-log-switches): Revise docstring.
(vc-git-shortlog-switches): New defcustom.
(vc-git-print-log): Use vc-git-log-switches or
vc-git-shortlog-switches depending on whether printing a shortlog.
(vc-git-log-outgoing, vc-git-log-incoming): Use
vc-git-shortlog-switches.
(vc-git-log-search, vc-git-expanded-log-entry): Use
vc-git-log-switches.
* etc/NEWS: Document the new defcustom.
This commit is contained in:
Sean Whitton 2022-12-04 15:56:35 -07:00
parent 3e00e50ee3
commit 5be502a697
2 changed files with 42 additions and 22 deletions

View file

@ -41,6 +41,13 @@ connection.
* Changes in Specialized Modes and Packages in Emacs 30.1
** VC
---
*** New user option 'vc-git-shortlog-switches'
String or list of strings giving Git log switches for shortlogs, such
as 'C-x v L'. 'vc-git-log-switches' is no longer used for shortlogs.
* New Modes and Packages in Emacs 30.1

View file

@ -136,12 +136,19 @@ If nil, use the value of `vc-annotate-switches'. If t, use no switches."
;;;###autoload(put 'vc-git-annotate-switches 'safe-local-variable (lambda (switches) (equal switches "-w")))
(defcustom vc-git-log-switches nil
"String or list of strings specifying switches for Git log under VC."
"String or list of strings giving Git log switches for non-shortlogs."
:type '(choice (const :tag "None" nil)
(string :tag "Argument String")
(repeat :tag "Argument List" :value ("") string))
:version "28.1")
(defcustom vc-git-shortlog-switches nil
"String or list of strings giving Git log switches for shortlogs."
:type '(choice (const :tag "None" nil)
(string :tag "Argument String")
(repeat :tag "Argument List" :value ("") string))
:version "30.1")
(defcustom vc-git-resolve-conflicts t
"When non-nil, mark conflicted file as resolved upon saving.
That is performed after all conflict markers in it have been
@ -1325,7 +1332,8 @@ If LIMIT is a revision string, use it as an end-revision."
,(format "--pretty=tformat:%s"
(car vc-git-root-log-format))
"--abbrev-commit"))
(ensure-list vc-git-log-switches)
(ensure-list
(if shortlog vc-git-shortlog-switches vc-git-log-switches))
(when (numberp limit)
(list "-n" (format "%s" limit)))
(when start-revision
@ -1340,16 +1348,16 @@ If LIMIT is a revision string, use it as an end-revision."
(defun vc-git-log-outgoing (buffer remote-location)
(vc-setup-buffer buffer)
(vc-git-command
buffer 'async nil
"log"
"--no-color" "--graph" "--decorate" "--date=short"
(format "--pretty=tformat:%s" (car vc-git-root-log-format))
"--abbrev-commit"
(concat (if (string= remote-location "")
"@{upstream}"
remote-location)
"..HEAD")))
(apply #'vc-git-command buffer 'async nil
`("log"
"--no-color" "--graph" "--decorate" "--date=short"
,(format "--pretty=tformat:%s" (car vc-git-root-log-format))
"--abbrev-commit"
,@(ensure-list vc-git-shortlog-switches)
,(concat (if (string= remote-location "")
"@{upstream}"
remote-location)
"..HEAD"))))
(defun vc-git-log-incoming (buffer remote-location)
(vc-setup-buffer buffer)
@ -1359,15 +1367,15 @@ If LIMIT is a revision string, use it as an end-revision."
;; so remove everything except a repository name.
(replace-regexp-in-string
"/.*" "" remote-location)))
(vc-git-command
buffer 'async nil
"log"
"--no-color" "--graph" "--decorate" "--date=short"
(format "--pretty=tformat:%s" (car vc-git-root-log-format))
"--abbrev-commit"
(concat "HEAD.." (if (string= remote-location "")
"@{upstream}"
remote-location))))
(apply #'vc-git-command buffer 'async nil
`("log"
"--no-color" "--graph" "--decorate" "--date=short"
,(format "--pretty=tformat:%s" (car vc-git-root-log-format))
"--abbrev-commit"
,@(ensure-list vc-git-shortlog-switches)
,(concat "HEAD.." (if (string= remote-location "")
"@{upstream}"
remote-location)))))
(defun vc-git-log-search (buffer pattern)
"Search the log of changes for PATTERN and output results into BUFFER.
@ -1378,6 +1386,7 @@ Display all entries that match log messages in long format.
With a prefix argument, ask for a command to run that will output
log entries."
(let ((args `("log" "--no-color" "-i"
,@(ensure-list vc-git-log-switches)
,(format "--grep=%s" (or pattern "")))))
(when current-prefix-arg
(setq args (cdr (split-string
@ -1462,7 +1471,11 @@ or BRANCH^ (where \"^\" can be repeated)."
(defun vc-git-expanded-log-entry (revision)
(with-temp-buffer
(apply #'vc-git-command t nil nil (list "log" revision "-1" "--no-color" "--"))
(apply #'vc-git-command t nil nil
`("log"
,revision
"-1" "--no-color" ,@(ensure-list vc-git-log-switches)
"--"))
(goto-char (point-min))
(unless (eobp)
;; Indent the expanded log entry.