From 9103aa64b64d0a79835c072086d040734ddf1c2a 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. --- lisp/vc/vc-annotate.el | 4 +++- lisp/vc/vc-git.el | 14 +++++++++++--- lisp/vc/vc-hooks.el | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) 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