Re: master 1d91d9b717d: project-vc-dir: Use truenames

Dmitry Gutov <[email protected]>
Newsgroups gmane.emacs.devel
Message-ID <[email protected]>
Hi,

On 23/07/2026 19:42, João Távora wrote:
> Indeed, when reading it it appears to do something different, but I've 
> tried it and it does the right thing. Seems it almost never follows the 
> link (which is good in my view). I don't quite understand the conditions 
> under which it does. Maybe the fact that it fooled two programmers 
> already justifies a comment?

I'm curious if either of you finds the same logic inside 
'vc-refresh-state' more legible. I've had to trace it back when writing 
the patch, so it was the reference to compare. ;-)

Anyway, how about this? Does it feel a bit repeating itself? I would 
rather remove the last sentence but as the author I'm probably not the 
best judge for that.

diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 1ba834d94cc..45e999d95a3 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -1990,14 +1990,21 @@ vc-dir

    (interactive
     (list
-    ;; When you hit C-x v d in a visited VC file,
-    ;; the *vc-dir* buffer visits the directory under its truename;
-    ;; therefore it makes sense to always do that.
-    ;; Otherwise if you do C-x v d -> C-x C-f -> C-x v d
-    ;; you may get a new *vc-dir* buffer, different from the original
-    (file-truename (read-directory-name "VC status for directory: "
-					(vc-root-dir) nil t
-					nil))
+    (let ((dir (read-directory-name "VC status for directory: "
+                                    (vc-root-dir) nil t
+                                    nil))
+          truename)
+      ;; Try to match the result of `vc-refresh-state' in a file buffer.
+      ;; Otherwise if you do C-x v d -> C-x C-f -> C-x v d you may get a
+      ;; new *vc-dir* buffer, different from the original.
+      ;; We use the truename if the DIR has no VC backend detected, but
+      ;; its truename differs, and has a VC backend.
+      (if (and vc-follow-symlinks
+               (not (vc-responsible-backend dir t))
+               (not (equal dir (setq truename (file-truename dir))))
+               (vc-responsible-backend truename t))
+          truename
+        dir))
      (if current-prefix-arg
  	(intern
  	 (completing-read
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.