* prevent vc-git.el from unnecessarily locking .git/index.lock
@ 2012-03-01 16:16 Ami Fischman
2012-03-26 3:08 ` Chong Yidong
0 siblings, 1 reply; 2+ messages in thread
From: Ami Fischman @ 2012-03-01 16:16 UTC (permalink / raw)
To: emacs-devel; +Cc: Alexandre Julliard, Dan Nicolaescu
[-- Attachment #1.1: Type: text/plain, Size: 507 bytes --]
Problem: starting with
15b73245<http://git.savannah.gnu.org/cgit/emacs.git/commit/lisp/vc-git.el?id=15b73245>
vc-git-state
(and thus anything that puts a file's git VC state in the modeline) causes
the git index to be locked periodically by emacs, even though it doesn't
need to. This causes rebases (or any other index-lock-needing operation)
run by the user in the same repository to fail, when the locks collide.
Proposed solution: the attached patch makes locking the index more
selective.
Cheers,
-a
[-- Attachment #1.2: Type: text/html, Size: 586 bytes --]
[-- Attachment #2: 0001-vc-git-state-don-t-git-add-refresh-except-if-no-diff.patch --]
[-- Type: text/x-patch, Size: 2247 bytes --]
From 75a7c4001414613c65cbd0dc19a5224f69d53a8d Mon Sep 17 00:00:00 2001
From: Dominique Quatravaux <domq@google.com>
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: prevent vc-git.el from unnecessarily locking .git/index.lock
2012-03-01 16:16 prevent vc-git.el from unnecessarily locking .git/index.lock Ami Fischman
@ 2012-03-26 3:08 ` Chong Yidong
0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2012-03-26 3:08 UTC (permalink / raw)
To: Ami Fischman; +Cc: Alexandre Julliard, Dan Nicolaescu, emacs-devel
Ami Fischman <ami@fischman.org> writes:
> Problem: starting with 15b73245 vc-git-state (and thus anything that
> puts a file's git VC state in the modeline) causes the git index to be
> locked periodically by emacs, even though it doesn't need to. This
> causes rebases (or any other index-lock-needing operation) run by the
> user in the same repository to fail, when the locks collide. Proposed
> solution: the attached patch makes locking the index more selective.
Looks reasonable. Committed; thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-03-26 3:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-01 16:16 prevent vc-git.el from unnecessarily locking .git/index.lock Ami Fischman
2012-03-26 3:08 ` Chong Yidong
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).