histedit: move locks into state
authorDavid Soria Parra <davidsp@fb.com>
Wed, 15 Oct 2014 08:38:36 -0700
changeset 22984 e0b5f5e3afe8
parent 22983 a3a981563ce8
child 22985 0c14b9166da6
histedit: move locks into state Allow action functions to control the locks. This is necessary for an implementation of x/exec or similar.
hgext/histedit.py
--- a/hgext/histedit.py	Wed Oct 15 08:38:16 2014 -0700
+++ b/hgext/histedit.py	Wed Oct 15 08:38:36 2014 -0700
@@ -190,12 +190,14 @@
 
 class histeditstate(object):
     def __init__(self, repo, parentctx=None, rules=None, keep=None,
-            topmost=None, replacements=None):
+            topmost=None, replacements=None, lock=None, wlock=None):
         self.repo = repo
         self.rules = rules
         self.keep = keep
         self.topmost = topmost
         self.parentctx = parentctx
+        self.lock = lock
+        self.wlock = wlock
         if replacements is None:
             self.replacements = []
         else:
@@ -537,15 +539,15 @@
     for intentional "edit" command, but also for resolving unexpected
     conflicts).
     """
-    lock = wlock = None
+    state = histeditstate(repo)
     try:
-        wlock = repo.wlock()
-        lock = repo.lock()
-        _histedit(ui, repo, *freeargs, **opts)
+        state.wlock = repo.wlock()
+        state.lock = repo.lock()
+        _histedit(ui, repo, state, *freeargs, **opts)
     finally:
-        release(lock, wlock)
+        release(state.lock, state.wlock)
 
-def _histedit(ui, repo, *freeargs, **opts):
+def _histedit(ui, repo, state, *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)
@@ -660,8 +662,11 @@
 
         parentctx = repo[root].parents()[0]
 
-        state = histeditstate(repo, parentctx, rules, keep, topmost,
-                    replacements)
+        state.parentctx = parentctx
+        state.rules = rules
+        state.keep = keep
+        state.topmost = topmost
+        state.replacements = replacements
 
     while state.rules:
         state.write()