From: Jim Porter <jporterbugs@gmail.com>
To: 67062@debbugs.gnu.org
Subject: bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git)
Date: Fri, 10 Nov 2023 18:49:59 -0800 [thread overview]
Message-ID: <66fc4912-6aa5-79da-bd6f-52f068cf1a77@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 683 bytes --]
Currently, when running 'vc-annotate' for a Git repo, the buffer name is
very long: it has the form "*Annotate FILE (rev REVISION)*", and for
Git, REVISION is 40(?) characters long. Seeing the full Git SHA isn't
(in my opinion) useful, especially not in a space-limited area like the
mode line. At the default width of 80 columns, this pushes much of the
mode line information off-screen.
Attached is a patch to add a 'short-revision' function for VC backends,
and a Git implementation for it.
Does this make sense? Should there be an option to restore the previous
behavior? (I'm not sure why anyone would *want* the old behavior, but
I'm not opposed to adding an option.)
[-- Attachment #2: 0001-Abbreviate-the-VC-revision-in-vc-annotate-s-buffer-n.patch --]
[-- Type: text/plain, Size: 3308 bytes --]
From 9103aa64b64d0a79835c072086d040734ddf1c2a Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
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
next reply other threads:[~2023-11-11 2:49 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-11 2:49 Jim Porter [this message]
2023-11-11 7:41 ` bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git) Eli Zaretskii
2023-11-11 21:31 ` Jim Porter
2023-11-11 22:00 ` Dmitry Gutov
2023-11-12 0:31 ` Jim Porter
2023-11-12 6:03 ` Eli Zaretskii
2023-11-12 10:58 ` Dmitry Gutov
2023-11-12 11:15 ` Eli Zaretskii
2023-11-12 11:21 ` Dmitry Gutov
2023-11-12 18:48 ` Juri Linkov
2023-11-12 20:37 ` Dmitry Gutov
2023-11-12 22:13 ` Jim Porter
2023-11-13 7:02 ` Juri Linkov
2023-11-13 14:04 ` Dmitry Gutov
2023-11-13 14:19 ` Eli Zaretskii
2023-12-14 19:42 ` Jim Porter
2023-12-14 19:51 ` Eli Zaretskii
2023-12-14 20:34 ` Jim Porter
2023-12-14 21:58 ` Dmitry Gutov
2023-12-15 0:06 ` Jim Porter
2023-12-15 0:15 ` Dmitry Gutov
2023-12-15 0:23 ` Jim Porter
2023-12-15 6:32 ` Eli Zaretskii
2023-12-15 6:36 ` Jim Porter
2023-12-15 8:50 ` Eli Zaretskii
2023-12-23 19:37 ` Jim Porter
2023-12-23 19:43 ` Dmitry Gutov
2023-12-23 19:49 ` Eli Zaretskii
2023-12-27 22:26 ` Jim Porter
2023-11-12 19:07 ` Jim Porter
2023-11-12 19:11 ` Eli Zaretskii
2023-11-12 19:33 ` Jim Porter
2023-11-12 20:35 ` Dmitry Gutov
2023-11-12 22:15 ` Jim Porter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=66fc4912-6aa5-79da-bd6f-52f068cf1a77@gmail.com \
--to=jporterbugs@gmail.com \
--cc=67062@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).