Subject: additional patch needed to set GIT_OPTIONAL_LOCKS=0 in all cases

From: Andrew Ruder <[email-masked]>
Date: Tue, 25 Sep 2018 05:23:10 -0700

Please see attached patch.  There is also some early reports of
success at https://github.com/magit/magit/issues/2708

In short, I believe the analysis for this bug was thorough (and
correct!), but it turns out that the call to `git status` doesn't
actually go through the patched function so we'd end up with a few
commands getting GIT_OPTIONAL_LOCKS=0 but not the most important one.

- Andrew Ruder

P.S. still figuring out the contribution process for emacs.
>From b2a4c67cdd6fe834317416120b96ab943d6a1f7a Mon Sep 17 00:00:00 2001
From: Andrew Ruder <[email-masked]>
Date: Mon, 24 Sep 2018 21:29:00 -0700
Subject: [PATCH] Fix for: "25.0.50; auto-revert-mode breaks git rebase"
 (Bug#21559)

The fix for Bug#21559 is mostly right, but the one command we were
trying to protect, git status --porcelain, doesn't go through
vc-git-command and wasn't actually getting the GIT_OPTIONAL_LOCKS=0
treatment.

* lisp/vc/vc-git.el (vc-git--call): Override GIT_OPTIONAL_LOCKS=0
  during revert-buffer-in-progress-p
---
 lisp/vc/vc-git.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index ca457fb3d1..cc137b2304 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1628,8 +1628,15 @@ vc-git--call
          (or coding-system-for-read vc-git-log-output-coding-system))
 	(coding-system-for-write
          (or coding-system-for-write vc-git-commits-coding-system))
-	(process-environment (cons "PAGER=" process-environment)))
-    (push "GIT_DIR" process-environment)
+	(process-environment
+	 (append
+	  `("GIT_DIR"
+	    "PAGER="
+	    ;; Avoid repository locking during background operations
+	    ;; (bug#21559).
+	    ,@(when revert-buffer-in-progress-p
+		'("GIT_OPTIONAL_LOCKS=0")))
+	  process-environment)))
     (apply 'process-file vc-git-program nil buffer nil command args)))
 
 (defun vc-git--out-ok (command &rest args)
-- 
2.17.0