Subject: bug#21559: PATCH review needed: lisp/vc/vc-git.el (vc-git-state, vc-git-conflicted-files)

From: Alexei Khlebnikov <[email-masked]>
Date: Mon, 19 Feb 2018 19:39:53 +0100

Eli, Michael, thanks for the review.

> A better approach would be to prepend "GIT_OPTIONAL_LOCKS=0" in `process-environment'.

Thanks for the suggestion, I am attaching version 2 of the patch which
implements this suggestion.

> > Adding to the discussion:
> > * Dmitry Gutov, because he is the maintainer for lisp/vc/* .
> > * Eli Zaretskii and Michael Albinus, because they participated in the discussion on this bug before.
>
> Thanks, but there's no need to add me: I read all the messages sent to
> the bug list.

OK, I've removed you from the addressees. I'm not sure if I should do
the same for others, so I left Dmitry and Michael in CC.
From 5265d04f908cdcab12b24402221b18d83fab1f43 Mon Sep 17 00:00:00 2001
From: Alexei Khlebnikov <[email-masked]>
Date: Mon, 19 Feb 2018 19:07:58 +0100
Subject: [PATCH v2] Fix for: "25.0.50; auto-revert-mode breaks git rebase"
 (Bug#21559)

* lisp/vc/vc-git.el (vc-git-state, vc-git-conflicted-files):
  Prepend "GIT_OPTIONAL_LOCKS=0" to process-environment
  when doing "git status".
---
 lisp/vc/vc-git.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 47172dd52f..35cb7defca 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -291,14 +291,17 @@ vc-git-state
   ;; corresponding upstream branch, and the file was modified
   ;; upstream.  We'd need to check against the upstream tracking
   ;; branch for that (an extra process call or two).
-  (let* ((args
+  (let* (;; Avoid repository locking during "git status" (bug#21559).
+         (process-environment
+          (cons "GIT_OPTIONAL_LOCKS=0" process-environment))
+         (args
           `("status" "--porcelain" "-z"
             ;; Just to be explicit, it's the default anyway.
             "--untracked-files"
             ,@(when (version<= "1.7.6.3" (vc-git--program-version))
                 '("--ignored"))
             "--"))
-        (status (apply #'vc-git--run-command-string file args)))
+         (status (apply #'vc-git--run-command-string file args)))
     ;; Alternatively, the `ignored' state could be detected with 'git
     ;; ls-files -i -o --exclude-standard', but that's an extra process
     ;; call, and the `ignored' state is rarely needed.
@@ -939,7 +942,10 @@ vc-git-merge-branch
 
 (defun vc-git-conflicted-files (directory)
   "Return the list of files with conflicts in DIRECTORY."
-  (let* ((status
+  (let* (;; Avoid repository locking during "git status" (bug#21559).
+         (process-environment
+          (cons "GIT_OPTIONAL_LOCKS=0" process-environment))
+         (status
           (vc-git--run-command-string directory "status" "--porcelain" "--"))
          (lines (when status (split-string status "\n" 'omit-nulls)))
          files)
-- 
2.15.1