From: Jim Porter <jporterbugs@gmail.com>
To: Dmitry Gutov <dmitry@gutov.dev>, Eli Zaretskii <eliz@gnu.org>
Cc: 67062@debbugs.gnu.org, juri@linkov.net
Subject: bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git)
Date: Thu, 14 Dec 2023 16:23:22 -0800 [thread overview]
Message-ID: <820bbb8d-0b46-97a3-58d7-c4af0a8bbc78@gmail.com> (raw)
In-Reply-To: <d0a4a2dc-78b8-2e25-a857-c51965fd9fed@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 588 bytes --]
On 12/14/2023 4:06 PM, Jim Porter wrote:
> While this patch does add a new backend action, it's purely optional and
> no other backend needs to be aware of it at all. I suppose I could
> hardcode the Git behavior in 'vc-short-revision', but that didn't seem
> to me to have any benefits over this version.
Actually, now that I think about it, I could add the 'vc-short-revision'
function and then use *that* to set a special variable, like so (see
attached). I'm not sure how much I like this, but it does completely
avoid adding any new backend functions (not even optional ones).
[-- Attachment #2: 0001-Abbreviate-the-VC-revision-in-vc-annotate-s-buffer-n.patch --]
[-- Type: text/plain, Size: 4063 bytes --]
From a5a564a90166933a1664e49243a31aa7b5996edf 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 | 8 ++++++++
lisp/vc/vc-annotate.el | 10 +++++++++-
lisp/vc/vc-git.el | 7 +++++--
lisp/vc/vc-hooks.el | 9 +++++++++
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 1ff2f8a149f..d8e7fd1d67f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -457,6 +457,14 @@ With this value only the revision number is displayed on the mode-line.
*** 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' function can show the
+revision in a shorter form, and 'vc-annotate' will use this form in
+its buffer name. Currently, this only applies to the Git backend. To
+restore the previous behavior, set 'vc-annotate-use-short-revision' to
+nil.
+
** Diff mode
+++
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 2e057ecfaa7..cc96ae8510a 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1835,8 +1835,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..a2d3a2616f6 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -506,6 +506,15 @@ vc-working-revision
(vc-call-backend
backend 'working-revision file))))))
+(defvar vc-use-short-revision nil)
+
+(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-15 0:23 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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=820bbb8d-0b46-97a3-58d7-c4af0a8bbc78@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.