[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ea4cbb3aae3: Abbreviate the VC revision in vc-annotate's buffer n

From: Jim Porter
Subject: master ea4cbb3aae3: Abbreviate the VC revision in vc-annotate's buffer name
Date: Wed, 27 Dec 2023 17:23:25 -0500 (EST)

branch: master
commit ea4cbb3aae3c7f72ef04337bc2db7292909ca9a1
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>

    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
    (vc-annotate): ... use it.
    * lisp/vc/vc-git.el (vc-git--rev-parse): Consult
    * etc/NEWS: Announce this change (bug#67062).
 etc/NEWS               |  6 ++++++
 lisp/vc/vc-annotate.el | 10 +++++++++-
 lisp/vc/vc-git.el      |  7 +++++--
 lisp/vc/vc-hooks.el    | 12 ++++++++++++
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index f82564946b7..c002ec33d45 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -497,6 +497,12 @@ switch is used, commands to see the diff of the old 
revision ('d'),
 check out an old file version ('f') or annotate it right away ('a'),
 also work on revisions which precede renames.
+*** 'vc-annotate' now abbreviates the Git revision in the buffer name.
+When using the Git backend, 'vc-annotate' will use an abbreviated
+revision identifier in its buffer name.  To restore the previous
+behavior, set 'vc-annotate-use-short-revision' to nil.
 *** New option 'vc-git-file-name-changes-switches'.
 It allows tweaking the thresholds for rename and copy detection.
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 @@ List of factors, used to expand/compress the time scale.  
See `vc-annotate'."
   :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 @@ should be applied to the background or to the foreground."
      (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
                (format-prompt "Annotate from revision" def)
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 24469f04f7c..bd74e2a6a44 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1857,8 +1857,11 @@ This requires git 1.8.4 or later, for the \"-L\" option 
of \"git log\"."
 (defun vc-git--rev-parse (rev)
-     (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..e84cdffe2dd 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -506,6 +506,18 @@ If FILE is not registered, this function always returns 
                             backend 'working-revision file))))))
+(defvar vc-use-short-revision nil
+  "If non-nil, VC backend functions should return short revisions if possible.
+This is set to t when calling `vc-short-revision', which will
+then call the \\=`working-revision' backend function.")
+(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)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]