From 0d55915e1984cb002b0f7b9a9e22d03c8b9431a7 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): Try to call 'short-revision'. * 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 | 6 +++++- lisp/vc/vc-git.el | 14 +++++++++++--- 3 files changed, 22 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..bee8cf23872 100644 --- a/lisp/vc/vc-annotate.el +++ b/lisp/vc/vc-annotate.el @@ -409,7 +409,11 @@ 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* ((short-rev (or (ignore-errors (vc-call-backend (vc-backend file) + 'short-revision rev)) + rev)) + (temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) + short-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'." -- 2.25.1