From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: dmitry@gutov.dev, 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:33:33 -0800 [thread overview]
Message-ID: <6335942d-b12b-1cdc-028f-d26722ea0d37@gmail.com> (raw)
In-Reply-To: <83zfziu6ra.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]
On 11/12/2023 11:11 AM, Eli Zaretskii wrote:
>> Date: Sun, 12 Nov 2023 11:07:38 -0800
>> Cc: 67062@debbugs.gnu.org
>> From: Jim Porter <jporterbugs@gmail.com>
>>
>> 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".
>
> Fine by me, except that I think this should be optional behavior.
Ok, how about this? If you think I should add a bit about this to the
manual, let me know. However, it seems like a fairly minor thing to me,
and I don't want to distract the manual reader from the more-useful parts.
(I also welcome a suggestion on a shorter name than
'vc-annotate-abbreviate-revision-in-buffer-name', but I wanted to be
careful not to give the impression that this would apply to the revision
IDs that you see in the VC-Annotate buffer's *contents*. I guess I could
abbreviate some of the existing words though, like "revision" -> "rev".)
[-- Attachment #2: 0001-Abbreviate-the-VC-revision-in-vc-annotate-s-buffer-n.patch --]
[-- Type: text/plain, Size: 3958 bytes --]
From 9726e1acb70d7d02648665cc259e174670ca839f 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-abbreviate-revision-in-buffer-name): New option...
(vc-annotate): ... use it, and try to call 'short-revision' when
requested.
* 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 | 7 +++++++
lisp/vc/vc-annotate.el | 13 ++++++++++++-
lisp/vc/vc-git.el | 14 +++++++++++---
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 767e4c27b43..df11757e18d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -396,6 +396,13 @@ 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.
+When the option 'vc-annotate-abbreviate-revision-in-buffer-name' is
+non-nil (the default), 'vc-annotate' will use an abbreviated revision
+in its buffer name if the VC backend has a 'vc-BACKEND-short-revision'
+function.
+
** Diff mode
+++
diff --git a/lisp/vc/vc-annotate.el b/lisp/vc/vc-annotate.el
index de6c3adbbdb..cacf05db6d9 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-abbreviate-revision-in-buffer-name 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
@@ -409,7 +414,13 @@ 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* ((displayed-rev
+ (or (and vc-annotate-abbreviate-revision-in-buffer-name
+ (ignore-errors (vc-call-backend (vc-backend file)
+ 'short-revision rev)))
+ rev))
+ (temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name)
+ displayed-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..05216701fa9 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)
+ "Return an abbreviated version of the revision REV."
+ (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:33 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
2023-11-12 19:11 ` Eli Zaretskii
2023-11-12 19:33 ` Jim Porter [this message]
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=6335942d-b12b-1cdc-028f-d26722ea0d37@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).