From 75a7c4001414613c65cbd0dc19a5224f69d53a8d Mon Sep 17 00:00:00 2001 From: Dominique Quatravaux Date: Thu, 1 Mar 2012 10:12:33 +0100 Subject: [PATCH] vc-git-state: don't git add --refresh except if no diff. Under `global-auto-revert-mode', `vc-git-state' is called periodically to update the mode line. It is therefore unsafe to grab the index.lock from this function (as git add --refresh does), as this may derail an ongoing git operation (especially a rebase). Only git add --refresh when it is useful, ie, when the file contents is identical to HEAD but the timestamp isn't. --- lisp/vc/vc-git.el | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index dbe591a..f1afba6 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -217,12 +217,20 @@ matching the resulting Git log output, and KEYWORDS is a list of ;; operation. (if (not (vc-git-registered file)) 'unregistered - (vc-git--call nil "add" "--refresh" "--" (file-relative-name file)) (let ((diff (vc-git--run-command-string - file "diff-index" "-z" "HEAD" "--"))) - (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0" + file "diff-index" "-p" "--raw" "-z" "HEAD" "--"))) + (if (and diff (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(\\(?:.\\|\n\\)*\\)\\'" diff)) - (vc-git--state-code (match-string 1 diff)) + (let ((diff-letter (match-string 1 diff)) + (diff-contents (match-string 2 diff))) + (if (not (string-match "\n." diff-contents)) + ;; Empty diff: file contents is the same as the HEAD + ;; revision, but timestamps are different (eg, file + ;; was "touch"ed). Update timestamp in index: + (prog1 'up-to-date + (vc-git--call nil "add" "--refresh" "--" + (file-relative-name file))) + (vc-git--state-code diff-letter))) (if (vc-git--empty-db-p) 'added 'up-to-date))))) (defun vc-git-working-revision (file) -- 1.7.7.3