Subject: 25.0.50; auto-revert-mode breaks git rebase
From: Ben Gamari <[email-masked]>
To: [email-masked]
Date: Fri, 25 Sep 2015 14:45:56 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

emacs running with `auto-revert-mode` enabled breaks `git rebase` in
repositories where files are open. The problem appears to be that
`auto-revert-mode` attempts to refresh version control information with
`vc-find-file-hook` on revert events. `vc-find-file-hook` calls out to
`git`, taking the repository's index lock.

This interferes badly with `git rebase`, which performs many git
commands in quick succession. When `auto-revert-mode` is enabled there
is a very high chance that the following race will occur,

    git                                  emacs
    ----------------------               -----------------------------
    1. git rebase checks out
       a commit, releases
       `index.lock`
                                         2. `auto-revert-mode` notices
                                            change, firing off a `git`
                                            process and taking `index.lock`.

    3. git rebase applies patch
       and attempts to commit.
       Notices that `index.lock`
       is taken and fails.

                                         4. emacs' `git` process
                                            finishes, releasing lock
                                          
In the end the user is left with a badly broken rebase process and an
error message complaining that `index.lock` exists, which he then goes
to confirm and finds no such file as emacs has already released the lock.

Arguably `git rebase` should be holding the `index.lock` for the entire
duration of the process (or be more resilient to the lock being taken)
but sadly this isn't the case. Emacs should behave appropriately to
accomodate this behavior.

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).

git version 2.5.1

In GNU Emacs 25.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.16.6)
 of 2015-08-20 on ben-laptop
Windowing system distributor `The X.Org Foundation', version 11.0.11702000
System Description:	Debian GNU/Linux testing (stretch)

Configured using:
 `configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs25:/etc/emacs:/usr/local/share/emacs/25.0/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/25.0/site-lisp:/usr/share/emacs/site-lisp
 --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs25:/etc/emacs:/usr/local/share/emacs/25.0/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/25.0/site-lisp:/usr/share/emacs/site-lisp
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat
 -Werror=format-security -Wall' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-z,relro'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  elisp-slime-nav-mode: t
  goto-address-prog-mode: t
  auto-highlight-symbol-mode: t
  clean-aindent-mode: t
  highlight-numbers-mode: t
  highlight-parentheses-mode: t
  rainbow-delimiters-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  helm-descbinds-mode: t
  helm-mode: t
  shell-dirtrack-mode: t
  projectile-global-mode: t
  projectile-mode: t
  recentf-mode: t
  winner-mode: t
  window-numbering-mode: t
  volatile-highlights-mode: t
  global-vi-tilde-fringe-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  savehist-mode: t
  popwin-mode: t
  global-page-break-lines-mode: t
  page-break-lines-mode: t
  Info-breadcrumbs-in-mode-line-mode: t
  ido-vertical-mode: t
  flx-ido-mode: t
  global-evil-surround-mode: t
  evil-surround-mode: t
  global-evil-search-highlight-persist: t
  evil-search-highlight-persist: t
  show-smartparens-global-mode: t
  show-smartparens-mode: t
  smartparens-mode: t
  evil-jumper-mode: t
  evil-escape-mode: t
  global-anzu-mode: t
  anzu-mode: t
  eval-sexp-fu-flash-mode: t
  company-mode: t
  global-hl-line-mode: t
  xterm-mouse-mode: t
  global-auto-revert-mode: t
  evil-leader-mode: t
  evil-mode: t
  evil-local-mode: t
  which-key-mode: t
  override-global-mode: t
  spacemacs-additional-leader-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  hs-minor-mode: t

Recent messages:
Resetting customization items...done
Creating customization setup...done
Creating customization items...
Creating group...
Creating group entries...done
Creating customization items ...done
Resetting customization items...done
Creating customization setup...done
Info-mouse-follow-link: Args out of range: 2394
Text is read-only [2 times]

Load-path shadows:
/home/ben/.emacs.d/elpa/helm-20150923.2134/helm-multi-match hides /home/ben/.emacs.d/elpa/helm-core-20150923.959/helm-multi-match
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-show hides /usr/local/share/emacs/site-lisp/notmuch-show
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-print hides /usr/local/share/emacs/site-lisp/notmuch-print
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-wash hides /usr/local/share/emacs/site-lisp/notmuch-wash
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-jump hides /usr/local/share/emacs/site-lisp/notmuch-jump
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-crypto hides /usr/local/share/emacs/site-lisp/notmuch-crypto
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-hello hides /usr/local/share/emacs/site-lisp/notmuch-hello
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-tree hides /usr/local/share/emacs/site-lisp/notmuch-tree
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch hides /usr/local/share/emacs/site-lisp/notmuch
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-address hides /usr/local/share/emacs/site-lisp/notmuch-address
/home/ben/.emacs.d/elpa/notmuch-20150907.527/coolj hides /usr/local/share/emacs/site-lisp/coolj
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-parser hides /usr/local/share/emacs/site-lisp/notmuch-parser
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-lib hides /usr/local/share/emacs/site-lisp/notmuch-lib
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-query hides /usr/local/share/emacs/site-lisp/notmuch-query
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-mua hides /usr/local/share/emacs/site-lisp/notmuch-mua
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-message hides /usr/local/share/emacs/site-lisp/notmuch-message
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-tag hides /usr/local/share/emacs/site-lisp/notmuch-tag
/home/ben/.emacs.d/elpa/notmuch-20150907.527/notmuch-maildir-fcc hides /usr/local/share/emacs/site-lisp/notmuch-maildir-fcc
/home/ben/.emacs.d/elpa/cmake-mode-20150817.725/cmake-mode hides /usr/share/emacs24/site-lisp/cmake-data/cmake-mode
/home/ben/.emacs.d/elpa/cmake-mode-20150817.725/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode
/usr/share/emacs/site-lisp/rst hides /usr/share/emacs/25.0.50/lisp/textmodes/rst
/home/ben/.emacs.d/elpa/seq-20150917.1508/seq hides /usr/share/emacs/25.0.50/lisp/emacs-lisp/seq

Features:
(shadow sort mail-extr warnings emacsbug message rfc822 mml mml-sec
mailabbrev gmm-utils mailheader sendmail mail-utils cus-edit cus-start
cus-load company-files company-keywords company-etags company-gtags
company-template company-dabbrev-code company-dabbrev company-capf
elisp-slime-nav goto-addr auto-highlight-symbol clean-aindent-mode
highlight-numbers parent-mode highlight-parentheses hideshow
rainbow-delimiters yasnippet jka-compr eieio-opt speedbar sb-image
ezimage dframe find-func helm-command helm-elisp helm-eval edebug
helm-descbinds helm-mode helm-files image-dired tramp tramp-compat
tramp-loaddefs trampver shell pcomplete format-spec dired-x dired-aux
ffap helm-buffers helm-elscreen helm-tags helm-bookmark helm-adaptive
helm-info bookmark helm-locate helm-grep helm-regexp helm-plugin
helm-external helm-net browse-url xml url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
url-parse auth-source gnus-util password-cache url-vars mailcap
helm-utils helm-help helm-types helm helm-source eieio-compat
helm-multi-match helm-lib dired projectile grep compile ibuf-ext ibuffer
recentf tree-widget disp-table server winner window-numbering etags xref
project volatile-highlights vi-tilde-fringe undo-tree diff solarized
smooth-scrolling smartparens-config saveplace savehist py-yapf powerline
powerline-separators color powerline-themes popwin page-break-lines
info+ ido-vertical-mode flx-ido flx ido exec-path-from-shell
evil-surround evil-search-highlight-persist evil-numbers evil-lisp-state
smartparens evil-jumper evil-indent-textobject evil-exchange evil-escape
evil-args evil-anzu anzu eval-sexp-fu rx highlight diminish company-web
company web-completion-data info tex-site adaptive-wrap hybrid-mode ielm
pp comint ansi-color hl-line xt-mouse autorevert filenotify
core-evilified-state evil-leader evil evil-integration evil-maps
evil-commands evil-command-window evil-types evil-search evil-ex
evil-macros evil-repeat evil-states evil-core evil-common windmove
thingatpt rect evil-digraphs evil-vars ring which-key quelpa
package-build mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 ietf-drums mm-util help-fns mail-prsvr json lisp-mnt use-package
bind-key s ucs-normalize dash wid-edit zenburn-theme
core-configuration-layer cl-seq finder-inf core-dotspacemacs ht cl
package epg-config eieio byte-opt bytecomp byte-compile cl-extra
help-mode easymenu seq cconv eieio-core cl-macs gv core-spacemacs
derived edmacro kmacro cl-loaddefs cl-lib core-evilify-keymap
core-keybindings easy-mmode core-use-package-ext core-micro-state corelv
core-toggle core-fonts-support core-spacemacs-buffer core-funcs
core-themes-support advice core-auto-completion core-release-management
core-emacs-backports subr-x pcase devhelp time-date mule-util tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
dbusbind inotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 854111 669089)
 (symbols 48 49466 68)
 (miscs 40 1968 2565)
 (strings 32 311688 272104)
 (string-bytes 1 11727672)
 (vectors 16 64346)
 (vector-slots 8 1157167 184119)
 (floats 8 1008 1405)
 (intervals 56 4139 1183)
 (buffers 976 26)
 (heap 1024 129296 66437))