From a5a564a90166933a1664e49243a31aa7b5996edf Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 14 Dec 2023 11:31:27 -0800 Subject: [PATCH] Abbreviate the VC revision in vc-annotate's buffer name * lisp/vc/vc-hooks.el (vc-use-short-revision): New variable. (vc-short-revision): New function. * lisp/vc/vc-annotate.el (vc-annotate-use-short-revision): New option... (vc-annotate): ... use it. * lisp/vc/vc-git.el (vc-git--rev-parse): Consult 'vc-use-short-revision'. * etc/NEWS: Announce this change (bug#67062). --- etc/NEWS | 8 ++++++++ lisp/vc/vc-annotate.el | 10 +++++++++- lisp/vc/vc-git.el | 7 +++++-- lisp/vc/vc-hooks.el | 9 +++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 1ff2f8a149f..d8e7fd1d67f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -457,6 +457,14 @@ With this value only the revision number is displayed on the mode-line. *** Obsolete command 'vc-switch-backend' re-added as 'vc-change-backend'. The command was previously obsoleted and unbound in Emacs 28. +--- +*** 'vc-annotate' can now abbreviate the revision in the buffer name. +VC backends with a 'vc-BACKEND-short-revision' function can show the +revision in a shorter form, and 'vc-annotate' will use this form in +its buffer name. Currently, this only applies to the Git backend. To +restore the previous behavior, set 'vc-annotate-use-short-revision' to +nil. + ** Diff mode +++ diff --git a/lisp/vc/vc-annotate.el b/lisp/vc/vc-annotate.el index de6c3adbbdb..cfca7cbfac0 100644 --- a/lisp/vc/vc-annotate.el +++ b/lisp/vc/vc-annotate.el @@ -162,6 +162,11 @@ vc-annotate-menu-elements :type '(repeat number) :group 'vc) +(defcustom vc-annotate-use-short-revision t + "If non-nil, \\[vc-annotate] will use short revisions in its buffer name." + :type 'boolean + :group 'vc) + (defvar-keymap vc-annotate-mode-map :doc "Local keymap used for VC-Annotate mode." "a" #'vc-annotate-revision-previous-to-line @@ -397,7 +402,10 @@ vc-annotate (save-current-buffer (vc-ensure-vc-buffer) (list buffer-file-name - (let ((def (vc-working-revision buffer-file-name))) + (let ((def (funcall (if vc-annotate-use-short-revision + #'vc-short-revision + #'vc-working-revision) + buffer-file-name))) (if (null current-prefix-arg) def (vc-read-revision (format-prompt "Annotate from revision" def) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 2e057ecfaa7..cc96ae8510a 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1835,8 +1835,11 @@ vc-git-previous-revision (defun vc-git--rev-parse (rev) (with-temp-buffer (and - (vc-git--out-ok "rev-parse" rev) - (buffer-substring-no-properties (point-min) (+ (point-min) 40))))) + (apply #'vc-git--out-ok "rev-parse" + (append (when vc-use-short-revision '("--short")) + (list rev))) + (goto-char (point-min)) + (buffer-substring-no-properties (point) (pos-eol))))) (defun vc-git-next-revision (file rev) "Git-specific version of `vc-next-revision'." diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 8451128286b..a2d3a2616f6 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -506,6 +506,15 @@ vc-working-revision (vc-call-backend backend 'working-revision file)))))) +(defvar vc-use-short-revision nil) + +(defun vc-short-revision (file &optional backend) + "Return the repository version for FILE in a shortened form. +If FILE is not registered, this function always returns nil." + (let ((vc-use-short-revision t)) + (vc-call-backend (or backend (vc-backend file)) + 'working-revision file))) + (defun vc-default-registered (backend file) "Check if FILE is registered in BACKEND using vc-BACKEND-master-templates." (let ((sym (vc-make-backend-sym backend 'master-templates))) -- 2.25.1