changeset 17326:23b2ee0f758d stable

histedit: add proper locking around repair.strip() calls
author Augie Fackler <raf@durin42.com>
date Wed, 01 Aug 2012 09:41:57 -0500
parents e4db509c08ec
children 7f5094bb3f42
files hgext/histedit.py
diffstat 1 files changed, 30 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Tue Jul 31 18:18:26 2012 +0200
+++ b/hgext/histedit.py	Wed Aug 01 09:41:57 2012 -0500
@@ -150,6 +150,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
@@ -492,11 +493,16 @@
         ui.debug('should strip temp nodes %s\n' %
                  ', '.join([node.hex(n)[:12] for n in tmpnodes]))
         for nodes in (created, tmpnodes):
-            for n in reversed(nodes):
-                try:
-                    repair.strip(ui, repo, n)
-                except error.LookupError:
-                    pass
+            lock = None
+            try:
+                lock = repo.lock()
+                for n in reversed(nodes):
+                    try:
+                        repair.strip(ui, repo, n)
+                    except error.LookupError:
+                        pass
+            finally:
+                lockmod.release(lock)
         os.unlink(os.path.join(repo.path, 'histedit-state'))
         return
     else:
@@ -636,19 +642,29 @@
 
         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 = None
+        try:
+            lock = repo.lock()
+            for n in sorted(replaced, key=lambda x: repo[x].rev()):
+                try:
+                    repair.strip(ui, repo, n)
+                except error.LookupError:
+                    pass
+        finally:
+            lockmod.release(lock)
+
+    ui.debug('should strip temp nodes %s\n' %
+             ', '.join([node.hex(n)[:12] for n in tmpnodes]))
+    lock = None
+    try:
+        lock = repo.lock()
+        for n in reversed(tmpnodes):
             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)
     os.unlink(os.path.join(repo.path, 'histedit-state'))
     if os.path.exists(repo.sjoin('undo')):
         os.unlink(repo.sjoin('undo'))