From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: dmitry@gutov.dev, 67062@debbugs.gnu.org, juri@linkov.net
Subject: bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git)
Date: Sat, 23 Dec 2023 11:37:24 -0800 [thread overview]
Message-ID: <0a95c0c4-3b45-4e29-7853-adaa5f4af328@gmail.com> (raw)
In-Reply-To: <834jgjq287.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 406 bytes --]
On 12/15/2023 12:50 AM, Eli Zaretskii wrote:
> Too vague, IMO.
>
> But I don't want to argue about this tiny detail for too long, I can
> always change the wording later if I think it's needed.
I rewrote the NEWS entry and added some more detail to the docstrings.
If no one has any objections, I'll merge this a bit after the new year
(so that people don't have to do code review during the holidays).
[-- Attachment #2: 0001-Abbreviate-the-VC-revision-in-vc-annotate-s-buffer-n.patch --]
[-- Type: text/plain, Size: 4239 bytes --]
From 706da4638a802660c9332a3bdaa980522ab7be44 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Thu, 14 Dec 2023 11:31:27 -0800
Subject: [PATCH] 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
option...
(vc-annotate): ... use it.
* lisp/vc/vc-git.el (vc-git--rev-parse): Consult
'vc-use-short-revision'.
* 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 6df17aa3f0a..7c21f04a0f7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -492,6 +492,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 @@ vc-annotate-menu-elements
: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 @@ vc-annotate
(save-current-buffer
(vc-ensure-vc-buffer)
(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
(vc-read-revision
(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 @@ vc-git-previous-revision
(defun vc-git--rev-parse (rev)
(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 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 @@ vc-working-revision
(vc-call-backend
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)))
--
2.25.1
next prev parent reply other threads:[~2023-12-23 19:37 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-11 2:49 bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git) Jim Porter
2023-11-11 7:41 ` 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 [this message]
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=0a95c0c4-3b45-4e29-7853-adaa5f4af328@gmail.com \
--to=jporterbugs@gmail.com \
--cc=67062@debbugs.gnu.org \
--cc=dmitry@gutov.dev \
--cc=eliz@gnu.org \
--cc=juri@linkov.net \
/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).