From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>, Dmitry Gutov <dmitry@gutov.dev>
Cc: 67062@debbugs.gnu.org
Subject: bug#67062: 30.0.50; [PATCH] Abbreviate the revision in 'vc-annotate' (for Git)
Date: Sun, 12 Nov 2023 11:07:38 -0800 [thread overview]
Message-ID: <399f2f1e-7c1f-e272-2a9d-4e36e8d8666b@gmail.com> (raw)
In-Reply-To: <83sf5bv77j.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]
On 11/11/2023 10:03 PM, Eli Zaretskii wrote:
>> Date: Sun, 12 Nov 2023 00:00:13 +0200
>> Cc: 67062@debbugs.gnu.org
>> From: Dmitry Gutov <dmitry@gutov.dev>
>>
>> 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.
>
> Which I think is the case here. What other VC backend has such long
> revision strings? I couldn't think of any.
Game of Trees[1] is one, though you could argue that that's cheating
because it uses the Git repository format. It does have a GNU ELPA
package though, so the author would probably want to add a
'vc-got-short-revision' function. (Or something similar depending on
what this patch looks like if/when it merges.) Looking at some GoT
repositories, they *do* still use the long SHA-1 hashes for revision
identifiers.
In fact, there are at least a couple Git-compatible VCSes now. Facebook
wrote one called "Sapling", though I haven't used it. Based on some
screenshots at least, it looks like Sapling also uses SHA-1 hashes for
revision IDs.
In any case, we don't necessarily need to provide a default
implementation for the 'short-revision' function. What about something
like this? I'm not sure it's better, but it does let us avoid defining a
no-op implementation for the "default backend".
[1] https://gameoftrees.org/index.html
[2] https://github.com/facebook/sapling
[-- Attachment #2: 0001-Abbreviate-the-VC-revision-in-vc-annotate-s-buffer-n.patch --]
[-- Type: text/plain, Size: 3351 bytes --]
From 0d55915e1984cb002b0f7b9a9e22d03c8b9431a7 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): Try to call 'short-revision'.
* 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 | 6 +++++-
lisp/vc/vc-git.el | 14 +++++++++++---
3 files changed, 22 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..bee8cf23872 100644
--- a/lisp/vc/vc-annotate.el
+++ b/lisp/vc/vc-annotate.el
@@ -409,7 +409,11 @@ 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* ((short-rev (or (ignore-errors (vc-call-backend (vc-backend file)
+ 'short-revision rev))
+ rev))
+ (temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name)
+ short-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'."
--
2.25.1
next prev parent reply other threads:[~2023-11-12 19:07 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
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 [this message]
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=399f2f1e-7c1f-e272-2a9d-4e36e8d8666b@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 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).