Subject: Re: bug#78890: 31.0.50; Messy vc-annotate buffer names

From: Sean Whitton <[email-masked]>
Date: Thu, 26 Jun 2025 16:06:37 +0100

Hello,

On Wed 25 Jun 2025 at 06:19pm +02, Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" wrote:

> On Wed, 25 Jun 2025 08:57:59 -0700 Jim Porter <[email-masked]> wrote:
>
>> On 6/25/2025 8:47 AM, Stephen Berman via Bug reports for GNU Emacs, the Swiss
>> army knife of text editors wrote:
>>> Oops, I should've checked instead of assuming.
>>> (https://www.imdb.com/title/tt0664250/quotes/?item=qt2409883)
>>
>> Well, when I looked at the code change, I'd have figured it would be in Emacs
>> 30 too, since that line is the same in 30 and the master branch. The bug is
>> new though, so something else changed, which worries me a little bit. It might
>> be a good idea to figure out what cause this regression in case it causes
>> other problems we're not aware of yet.
>
> I checked now, and in emacs-30 the current buffer when temp-buffer-name
> is set is the one visiting the file being annotated, while in master
> it's the buffer displaying the annotations.  In emacs-30 there is a call
> to `vc-ensure-vc-buffer' before the let sexp where temp-buffer-name is
> set, but not in master; adding that back seems to fix the problem.

Thanks for looking again and figuring this out.

Removing vc-ensure-vc-buffer was intentional, and it shouldn't just go
back -- that was part of adding vc-buffer-overriding-fileset.  What do
you both think to something like this:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/vc/vc-annotate.el b/lisp/vc/vc-annotate.el
index de432e4e1c3..99df932af83 100644
--- a/lisp/vc/vc-annotate.el
+++ b/lisp/vc/vc-annotate.el
@@ -419,7 +419,12 @@ vc-annotate
 		       (read-string (format-prompt "Annotate span days" 20)
 				    nil nil "20"))))))))
   (setq vc-annotate-display-mode display-mode) ;Not sure why.  --Stef
-  (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev))
+  (let* ((file-buffer (get-file-buffer file))
+         (temp-buffer-name (format "*Annotate %s (rev %s)*"
+                                   (if file-buffer
+                                       (buffer-name file-buffer)
+                                     file)
+                                   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
--8<---------------cut here---------------end--------------->8---

-- 
Sean Whitton