[PATCH stable] histedit: add proper locking around repair.strip() calls

Augie Fackler raf at durin42.com
Wed Aug 1 08:22:36 CDT 2012


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1343772411 18000
# Branch stable
# Node ID 07af978f9019634f1cdcdac3c3d04de992038fe4
# Parent  98166640b356b4c44bc87ce9137c7647eb728332
histedit: add proper locking around repair.strip() calls

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -152,6 +152,7 @@
 from mercurial import discovery
 from mercurial import error
 from mercurial import hg
+from mercurial import lock as lockmod
 from mercurial import node
 from mercurial import patch
 from mercurial import repair
@@ -497,10 +498,17 @@
                  ', '.join([node.hex(n)[:12] for n in tmpnodes]))
         for nodes in (created, tmpnodes):
             for n in reversed(nodes):
+                wlock = lock = None
                 try:
-                    repair.strip(ui, repo, n)
-                except error.LookupError:
-                    pass
+                    wlock = repo.wlock()
+                    lock = repo.lock()
+
+                    try:
+                        repair.strip(ui, repo, n)
+                    except error.LookupError:
+                        pass
+                finally:
+                    lockmod.release(lock, wlock)
         os.unlink(os.path.join(repo.path, 'histedit-state'))
         return
     else:
@@ -640,18 +648,30 @@
         ui.debug('should strip replaced nodes %s\n' %
                  ', '.join([node.hex(n)[:12] for n in replaced]))
         for n in sorted(replaced, key=lambda x: repo[x].rev()):
+            lock = wlock = None
+            try:
+                wlock = repo.wlock()
+                lock = repo.lock()
+                try:
+                    repair.strip(ui, repo, n)
+                except error.LookupError:
+                    pass
+            finally:
+                lockmod.release(lock, wlock)
+
+    ui.debug('should strip temp nodes %s\n' %
+             ', '.join([node.hex(n)[:12] for n in tmpnodes]))
+    for n in reversed(tmpnodes):
+        lock = wlock = None
+        try:
+            wlock = repo.wlock()
+            lock = repo.lock()
             try:
                 repair.strip(ui, repo, n)
             except error.LookupError:
                 pass
-
-    ui.debug('should strip temp nodes %s\n' %
-             ', '.join([node.hex(n)[:12] for n in tmpnodes]))
-    for n in reversed(tmpnodes):
-        try:
-            repair.strip(ui, repo, n)
-        except error.LookupError:
-            pass
+        finally:
+            lockmod.release(lock, wlock)
     os.unlink(os.path.join(repo.path, 'histedit-state'))
     if os.path.exists(repo.sjoin('undo')):
         os.unlink(repo.sjoin('undo'))


More information about the Mercurial-devel mailing list