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

From: Ben Gamari <[email-masked]>
Date: Mon, 28 Sep 2015 16:11:16 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Ben Gamari <[email-masked]>
>> Date: Fri, 25 Sep 2015 14:45:56 +0200
>> 
>> One imperfect workaround would be to instead schedule a worker to call
>> `vc-fine-file-hook` at some point in the future when the repository is
>> more likely to be idle (for instance, when there have been no change
>> events for a second or so).
>
> But autorevert already does exactly that: it doesn't act on file
> changes immediately, only once every N seconds.  N defaults to 5,
> perhaps you could try customizing auto-revert-interval to a larger
> value to see if that solves the problem.
>
This is not true is auto-revert-use-notify is enabled.

If I'm not mistaken, your suggestion amounts to increasing the poll
interval. This will never solve the problem, it will only mean that the
race has fewer opportunities to pop up. Of course, the same can be said
of my suggestion, which only narrows the race window, not remove it
altogether (which is sadly not possible without fixing git rebase).

As an aside, it came as quite a surprise that autorevert (if I
understand the code correctly) still polls even if
auto-revert-use-notify is set. It seems to me that this is itself a bug.
As a laptop user who often works on battery, I keep tabs on which
processes eat CPU time and I have noticed that emacs is consistently
behind only firefox and Xorg in CPU time demanded at idle.

> In any case, the issue here is that Emacs doesn't know when "the
> repository is idle".  If someone can suggest how to tell that,
> autorevert could be augmented not to revert VC files while the
> repository is "busy".  From your description I understand that just
> looking at index.lock is not good enough, since Git releases it more
> than once in this scenario, while the rebase operation is still
> on-going.
>
Right.

I threw together a patch [1] implementing the suggestion I presented
above. I have yet to rigorously test it but I have yet to experience the
issue since starting to use it.

> Btw, what is your value of auto-revert-check-vc-info?  If it's
> non-nil, perhaps resetting it to nil will also avoid these problems.

It is nil but this doesn't matter as vc-find-file-hook is called if
either auto-revert-check-vc-info or the revert flag are set.

Cheers,

- Ben

[1] https://github.com/bgamari/emacs/compare/master...auto-revert-vc-idle