emacs-31 bc92224c5f1: VC-Git: Pass --no-optional-locks

Sean Whitton <[email protected]> Wed, 5 Aug 2026 09:33:59 -0400 (EDT)
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: emacs-31
commit bc92224c5f163f94f80b29dae744a488dd675e0a
Author: Sean Whitton <[email protected]>
Commit: Sean Whitton <[email protected]>

    VC-Git: Pass --no-optional-locks
    
    * lisp/vc/vc-git.el (vc-git--no-optional-locks): New function.
    (vc-git-command, vc-git--call): Use it.
---
 lisp/vc/vc-git.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 17c358e25d5..34b10dedf96 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -2899,6 +2899,13 @@ page for the meanings of these attributes."
                (equal subcommand "status"))
            '("GIT_OPTIONAL_LOCKS=0"))))
 
+;; This is for the same purpose as `vc-git--env-vars' except that it
+;; covers older Git, which doesn't recognise the environment variable.
+(defun vc-git--no-optional-locks (subcommand)
+  (and (or revert-buffer-in-progress
+           (equal subcommand "status"))
+       '("--no-optional-locks")))
+
 (defun vc-git-command (buffer okstatus file-or-list &rest flags)
   "A wrapper around `vc-do-command' for use in vc-git.el.
 The difference to `vc-do-command' is that this function always invokes
@@ -2944,7 +2951,9 @@ The difference to `vc-do-command' is that this function always invokes
                   ".")
                  ((not file-list-is-rootdir)
                   file-or-list))
-           (cons "--no-pager" flags))))
+           (cons "--no-pager"
+                 (append (vc-git--no-optional-locks (car flags))
+                         flags)))))
 
 (defun vc-git--empty-db-p ()
   "Check if the git db is empty (no commit done yet)."
@@ -2964,7 +2973,9 @@ The difference to `vc-do-command' is that this function always invokes
 	(process-environment (append (vc-git--env-vars command)
                                      process-environment)))
     (apply #'process-file vc-git-program infile buffer nil
-           "--no-pager" command args)))
+           (cons "--no-pager"
+                 (append (vc-git--no-optional-locks command)
+                         (cons command args))))))
 
 (defun vc-git--out-ok (command &rest args)
   "Run `git COMMAND ARGS...' and insert standard output in current buffer.