[PATCH 2 of 5 V2] histedit: refactor repo locking

Olle Lundberg olle.lundberg at gmail.com
Thu Mar 6 05:26:15 CST 2014


# HG changeset patch
# User Olle Lundberg <geek at nerd.sh>
# Date 1394064851 -3600
#      Thu Mar 06 01:14:11 2014 +0100
# Node ID 0f4009fb0e1373e4fa9d5814f8f41e49bb3ec37b
# Parent  7f824b2d4f11b56680693090804c20fa6b05e790
histedit: refactor repo locking

Introdcuce a new global lock manager object that holds a global
repo lock. This way we can release locks for running hg within
hg.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -433,10 +433,28 @@
         msg = _('there are ambiguous outgoing revisions')
         hint = _('see "hg help histedit" for more detail')
         raise util.Abort(msg, hint=hint)
     return repo.lookup(roots[0])
 
+class _lockmgr(object):
+    def __init__(self, repo):
+        self.__repo = repo
+        self.__lock = self.__wlock = None
+
+    def takelocks(self):
+        if self.__wlock is None:
+            self.__wlock = self.__repo.wlock()
+        if self.__lock is None:
+            self.__lock = self.__repo.lock()
+
+    def releaselocks(self):
+        release(self.__lock, self.__wlock)
+        self.__lock = self.__wlock = None
+
+
+_toprepolock = None
+
 actiontable = {'p': pick,
                'pick': pick,
                'e': edit,
                'edit': edit,
                'f': fold,
@@ -480,17 +498,17 @@
 
     Returns 0 on success, 1 if user intervention is required (not only
     for intentional "edit" command, but also for resolving unexpected
     conflicts).
     """
-    lock = wlock = None
     try:
-        wlock = repo.wlock()
-        lock = repo.lock()
+        global _toprepolock
+        _toprepolock = _lockmgr(repo)
+        _toprepolock.takelocks()
         _histedit(ui, repo, *freeargs, **opts)
     finally:
-        release(lock, wlock)
+        _toprepolock.releaselocks()
 
 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)


More information about the Mercurial-devel mailing list