Subject: Re: bug#26345: [PATCH] Handle renamed files when cycling through revisions

From: Jakub Ječmínek <[email-masked]>
Date: Mon, 7 Jul 2025 23:09:18 +0200

On 7/7/25 10:34, Sean Whitton wrote:
> That's okay, I think the only thing is to check that the backend
> implements file-name-changes using vc-find-backend-function.  Then so
> long as the general approach makes sense and works for Git it's fine.

I've updated the patch based on your suggestions. You're right, 
`vc-annotate' is indeed a better place for this change.

>> Dmitry Gutov <[email-masked]> writes:
>>
>>> On 05/07/2025 19:42, Sean Whitton wrote:
>>> I think (?) the file name might have changed in some later revision - so
>>> it won't be returned by vc-git-file-name-changes for that specific REV,
>>> but still might not match the current name.
>>
>> I'm not sure.
> 
> Seems like this needs to be investigated before we can proceed.
I've tested various scenarios and haven't encountered any issues with 
the current implementation. It would be great if you could test the 
change as well, in case there are edge cases I missed.

From 5c4108a0c243d54c8d2440eb1bca06fa57fae32e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Je=C4=8Dm=C3=ADnek?= <[email-masked]>
Date: Mon, 7 Jul 2025 22:32:57 +0200
Subject: [PATCH] Handle renamed files when cycling through revisions

* lisp/vc/vc-annotate.el (vc-annotate, vc-annotate--file-name-change):
Update the FILE argument passed to `annotate-command' based on
possible file name changes in the specified revision using the
new function `vc-annotate--file-name-change'.
---
 lisp/vc/vc-annotate.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/vc-annotate.el b/lisp/vc/vc-annotate.el
index e68c5a79919..8829894decf 100644
--- a/lisp/vc/vc-annotate.el
+++ b/lisp/vc/vc-annotate.el
@@ -459,7 +459,8 @@ vc-annotate
             (setq coding-system-for-read
                   (coding-system-change-eol-conversion coding-system-for-read
                                                        'dos)))
-        (vc-call-backend backend 'annotate-command file
+        (vc-call-backend backend 'annotate-command
+                         (vc-annotate--file-name-change file rev backend)
                          (get-buffer temp-buffer-name) rev)
         ;; we must setup the mode first, and then set our local
         ;; variables before the show-function is called at the exit of
@@ -804,6 +805,14 @@ vc-annotate-goto-line
       (message "Annotations were for revision %s; line numbers may be incorrect"
 	       rev)))))
 
+(defun vc-annotate--file-name-change (file rev backend)
+  "Return the name of FILE at revision REV using BACKEND.
+If the file name has changed in the given revision, return the new name;
+otherwise, return FILE unchanged."
+  (if (vc-find-backend-function backend 'file-name-changes)
+      (or (cdr (assoc file (vc-call-backend backend 'file-name-changes rev))) file)
+    file))
+
 (provide 'vc-annotate)
 
 ;;; vc-annotate.el ends here
-- 
2.49.0