Subject: bug#39452: [PATCH] vc-git-state fails for filenames with wildcards

From: Dmitry Gutov <[email-masked]>
Date: Mon, 30 Aug 2021 05:36:06 +0300

On 27.08.2021 22:57, Stephen Berman wrote:
> I just discovered that some code I have that uses vc-print-log-internal
> broke after the literal-pathspecs change; specifically, my code passes a
> directory name beginning with "~/" to vc-print-log-internal, and this
> had worked fine till that change, which broke it, and I found I have to
> wrap the directory name in expand-file-name to make the code work again.
> Is this expected fallout from that change or was I perhaps misusing
> vc-print-log-internal and was just lucky that it had worked before?

Here's a patch which restores vc-print-log-internal's behavior without 
major changes. Check it out (attached).
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 1cd200cd13..a5431abb40 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -245,7 +245,11 @@ vc-git-update-on-retrieve-tag
 (defun vc-git--literal-pathspec (file)
   "Prepend :(literal) path magic to FILE."
   ;; Good example of file name that needs this: "test[56].xx".
-  (and file (concat ":(literal)" (file-local-name file))))
+  (let ((lname (file-local-name file)))
+    ;; Expand abbreviated file names.
+    (when (file-name-absolute-p lname)
+      (setq lname (expand-file-name lname)))
+    (and file (concat ":(literal)" lname))))
 
 (defun vc-git--literal-pathspecs (files)
   "Prepend :(literal) path magic to FILES."
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index b75862e8a5..f0f5809d99 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2055,9 +2055,9 @@ vc-root-diff
       ;; here, this way the *vc-diff* buffer is setup correctly, so
       ;; relative file names work.
       (let ((default-directory rootdir))
-	(vc-diff-internal
-	 t (list backend (list (expand-file-name rootdir)) working-revision) nil nil
-	 (called-interactively-p 'interactive))))))
+        (vc-diff-internal
+         t (list backend (list rootdir) working-revision) nil nil
+         (called-interactively-p 'interactive))))))
 
 ;;;###autoload
 (defun vc-root-dir ()
@@ -2603,8 +2603,8 @@ vc-print-root-log
       (setq backend (vc-responsible-backend rootdir))
       (unless backend
         (error "Directory is not version controlled")))
-    (setq default-directory (expand-file-name rootdir))
-    (vc-print-log-internal backend (list default-directory) revision revision limit
+    (setq default-directory rootdir)
+    (vc-print-log-internal backend (list rootdir) revision revision limit
                            (when with-diff 'with-diff))))
 
 ;;;###autoload