[PATCH] histedit: hold wlock and lock while in progress

Siddharth Agarwal sid0 at fb.com
Sun Nov 17 17:40:56 CST 2013


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1384729869 28800
#      Sun Nov 17 15:11:09 2013 -0800
# Node ID 856587a47e937114e45e686dbbf172a789c33c64
# Parent  5e301ca90b26c64d2bfaa6f9e50007778c96df0a
histedit: hold wlock and lock while in progress

Currently, histedit acquires and releases lock and wlock several times during
its run. This isn't great because it allows other hg processes to come in and
change state. With this fix, lock and wlock are acquired and released exactly
once.

The change to test-histedit-drop.t is a minor implementation one -- the cache
is still correctly invalidated, but it just happens a little later and only
gets printed out because of the unrelated --debug flag.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -159,6 +159,7 @@
 from mercurial import util
 from mercurial import obsolete
 from mercurial import merge as mergemod
+from mercurial.lock import release
 from mercurial.i18n import _
 
 cmdtable = {}
@@ -476,6 +477,15 @@
     for intentional "edit" command, but also for resolving unexpected
     conflicts).
     """
+    lock = wlock = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        _histedit(ui, repo, *freeargs, **opts)
+    finally:
+        release(lock, wlock)
+
+def _histedit(ui, repo, *freeargs, **opts):
     # TODO only abort if we try and histedit mq patches, not just
     # blanket if mq patches are applied somewhere
     mq = getattr(repo, 'mq', None)
diff --git a/tests/test-histedit-drop.t b/tests/test-histedit-drop.t
--- a/tests/test-histedit-drop.t
+++ b/tests/test-histedit-drop.t
@@ -97,6 +97,7 @@
 Check histedit_source
 
   $ hg log --debug --rev f518305ce889
+  invalid branchheads cache (visible): tip differs
   changeset:   4:f518305ce889c07cb5bd05522176d75590ef3324
   tag:         tip
   phase:       draft


More information about the Mercurial-devel mailing list