Subject: bug#21559: 25.0.50; auto-revert-mode breaks git rebase

From: Dmitry Gutov <[email-masked]>
Date: Tue, 20 Feb 2018 01:41:55 +0200

On 2/15/18 9:08 PM, Alexei Khlebnikov wrote:
> Judging from the comment of the commit implementing the 
> "--no-optional-locks" switch,
> 
> https://github.com/git/git/commit/27344d6a6c8056664966e11acf674e5da6dd7ee3
> ​
> , the switch was implemented exactly for background refresh in "tools 
> like IDEs or fancy editors".
> I.e. for mitigating this particular bug! Now we only have to use this 
> switch in our "fancy editor".

OK, here's my question: what is a "background refresh"? Must be consider 
every VC operation to be "background"?

 From what I see of this switch's description, it's going to (slightly? 
imperceptibly?) slow down the VC operations. It would be cool to see 
some measurement of that effect.

Failing that, why don't we try something else first? If the problem 
occurs solely due to auto-revert-mode's calls to Git, let's try adding 
that environment variable binding inside auto-revert-handler. The patch 
is below. Does it solve the problem as well?

diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index cf145e0ee3..41e9f00049 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -709,7 +709,9 @@ auto-revert-handler
      ;; `preserve-modes' avoids changing the (minor) modes.  But we do
      ;; want to reset the mode for VC, so we do it manually.
      (when (or revert auto-revert-check-vc-info)
-      (vc-refresh-state))))
+      (let ((process-environment
+             (cons "GIT_OPTIONAL_LOCKS=0" process-environment)))
+        (vc-refresh-state)))))

  (defun auto-revert-tail-handler (size)
    (let ((modified (buffer-modified-p))