Patchwork [9,of,9] histedit: move locks into state

login
register
mail settings
Submitter David Soria Parra
Date Oct. 16, 2014, 5:34 p.m.
Message ID <09c782cf1370854473f5.1413480885@davidsp-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/6342/
State Accepted
Headers show

Comments

David Soria Parra - Oct. 16, 2014, 5:34 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1413387516 25200
#      Wed Oct 15 08:38:36 2014 -0700
# Node ID 09c782cf1370854473f5c307dd647f53e66a4288
# Parent  57e8a9f0368388c5bc3db11a13c8a17a72c6b184
histedit: move locks into state

Allow action functions to control the locks. This is necessary for
an implementation of x/exec or similar.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -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()