From 3dd9434161b36f01397c3269ca839bca3db0d59e Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Fri, 10 Nov 2023 18:42:29 -0800 Subject: [PATCH] Abbreviate the VC revision in vc-annotate's buffer name * lisp/vc/vc-annotate.el (vc-annotate): Call 'short-revision' * lisp/vc/vc-hooks.el (vc-default-short-revision): New function. * lisp/vc/vc-git.el (vc-git-short-revision): New function. (vc-git--rev-parse): New optional argument SHORT. * etc/NEWS: Announce this change (bug#67062). --- etc/NEWS | 6 ++++++ lisp/vc/vc-annotate.el | 4 +++- lisp/vc/vc-git.el | 14 +++++++++++--- lisp/vc/vc-hooks.el | 5 +++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 767e4c27b43..0632001648c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -396,6 +396,12 @@ switches for shortlogs, such as the one produced by 'C-x v L'. *** 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' functions can convert a +revision to a shorter form, and 'vc-annotate' will use this form in +its buffer name. Currently, the Git backend supports this. + ** Diff mode +++ diff --git a/lisp/vc/vc-annotate.el b/lisp/vc/vc-annotate.el index de6c3adbbdb..85161347cbf 100644 --- a/lisp/vc/vc-annotate.el +++ b/lisp/vc/vc-annotate.el @@ -409,7 +409,9 @@ vc-annotate nil nil "20"))))))) (vc-ensure-vc-buffer) (setq vc-annotate-display-mode display-mode) ;Not sure why. --Stef - (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev)) + (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) + (vc-call-backend (vc-backend file) + 'short-revision rev))) (temp-buffer-show-function 'vc-annotate-display-select) ;; If BUF is specified, we presume the caller maintains current line, ;; so we don't need to do it here. This implementation may give diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 707fc7cfc07..2ff6f5564ed 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -403,6 +403,11 @@ vc-git-working-revision (let (process-file-side-effects) (vc-git--rev-parse "HEAD"))) +(defun vc-git-short-revision (rev) + "Git-specific version of `vc-short-revision'." + (let (process-file-side-effects) + (vc-git--rev-parse rev 'short))) + (defun vc-git--symbolic-ref (file) (or (vc-file-getprop file 'vc-git-symbolic-ref) @@ -1830,11 +1835,14 @@ vc-git-previous-revision ;; does not (and cannot) quote. (vc-git--rev-parse (concat rev "~1")))) -(defun vc-git--rev-parse (rev) +(defun vc-git--rev-parse (rev &optional short) (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 short '("--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 c16fb63b2ff..38c84a0ceea 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -502,6 +502,11 @@ vc-working-revision (vc-call-backend backend 'working-revision file)))))) +(defun vc-default-short-revision (_backend rev) + "Return a \"shortened\" version of the revision REV. +This default implementation simply returns REV unchanged." + rev) + (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