From: Jim Porter <jporterbugs@gmail.com>
To: Dmitry Gutov <dmitry@gutov.dev>, Eli Zaretskii <eliz@gnu.org>
Cc: 67062@debbugs.gnu.org
Subject: bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git)
Date: Sat, 11 Nov 2023 16:31:43 -0800 [thread overview]
Message-ID: <2f7f9967-496c-163a-fa46-58b255a7e8a0@gmail.com> (raw)
In-Reply-To: <2eb31324-ae24-db4b-4f62-a0140bfb9f81@gutov.dev>
[-- Attachment #1: Type: text/plain, Size: 1290 bytes --]
On 11/11/2023 2:00 PM, Dmitry Gutov wrote:
> On 11/11/2023 09:41, Eli Zaretskii wrote:
>> If this is a Git-only issue, perhaps it would be better to have a
>> Git-only option, instead of defining a whole new VC method?
>
> Our general approach is to prefer global options and dynamic dispatch on
> backends, resorting to using per-backend options when it's much easier
> to do.
>
> In this case it might actually be more difficult to go the second route
> since the intention is to only use the short hash in this particular
> place. vc-annotate is common code and it will need to indicate that
> intention to the backend somehow.
Thanks for taking a look. It sounds like the strategy I went with is at
least approximately right, so here's an updated patch with a NEWS entry.
I looked through the manuals and didn't see anywhere to add a mention of
this though. There's a section about 'vc-annotate', but it's written for
an Emacs user, rather than an Elisp programmer, and I think trying to
explain "short revisions" in that section would just add unnecessary
detail. If we still want to add some mention of this to a manual, I
guess it would make the most sense in some section about how to use the
VC package as an Elisp programmer. I didn't see much about that though...
[-- Attachment #2: 0001-Abbreviate-the-VC-revision-in-vc-annotate-s-buffer-n.patch --]
[-- Type: text/plain, Size: 4017 bytes --]
From 3dd9434161b36f01397c3269ca839bca3db0d59e 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.
* etc/NEWS: Announce this change (bug#67062).
---
etc/NEWS | 6 ++++++
lisp/vc/vc-annotate.el | 4 +++-
lisp/vc/vc-git.el | 14 +++++++++++---
lisp/vc/vc-hooks.el | 5 +++++
4 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 767e4c27b43..0632001648c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -396,6 +396,12 @@ switches for shortlogs, such as the one produced by 'C-x v L'.
*** 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' functions can convert a
+revision to a shorter form, and 'vc-annotate' will use this form in
+its buffer name. Currently, the Git backend supports this.
+
** Diff mode
+++
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 prev parent reply other threads:[~2023-11-12 0:31 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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2f7f9967-496c-163a-fa46-58b255a7e8a0@gmail.com \
--to=jporterbugs@gmail.com \
--cc=67062@debbugs.gnu.org \
--cc=dmitry@gutov.dev \
--cc=eliz@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 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.