[PATCH 18 of 19] bookmarks: primarily use repo lock, not wlock

Mads Kiilerich mads at kiilerich.com
Thu Jan 12 19:32:52 CST 2012


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1326418243 -3600
# Node ID 87bc847a7ede54c4c1637e07d3ac31da08adb944
# Parent  d8fc79ea94e0c7179546af7c42ef02615770273a
bookmarks: primarily use repo lock, not wlock

Bookmarks are repository data, not working directory data. Only the current
bookmark is working directory data.

Some lock shuffling is required to avoid lockout between the initial mock lock
and locking of the localrepo instance that is created after copying.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -84,7 +84,7 @@
             raise util.Abort(_("bookmark '%s' contains illegal "
                 "character" % mark))
 
-    wlock = repo.wlock()
+    lock = repo.lock()
     try:
 
         file = repo.opener('bookmarks', 'w', atomictemp=True)
@@ -99,7 +99,7 @@
             pass
 
     finally:
-        wlock.release()
+        lock.release()
 
 def setcurrent(repo, mark):
     '''Set the name of the bookmark that we are currently on
@@ -117,13 +117,13 @@
         raise util.Abort(_("bookmark '%s' contains illegal "
             "character" % mark))
 
-    wlock = repo.wlock()
+    lock = repo.lock()
     try:
         file = repo.opener('bookmarks.current', 'w', atomictemp=True)
         file.write(encoding.fromlocal(mark))
         file.close()
     finally:
-        wlock.release()
+        lock.release()
     repo._bookmarkcurrent = mark
 
 def updatecurrentbookmark(repo, oldnode, curbranch):
@@ -162,7 +162,7 @@
     return d
 
 def pushbookmark(repo, key, old, new):
-    w = repo.wlock()
+    lock = repo.lock()
     try:
         marks = repo._bookmarks
         if hex(marks.get(key, '')) != old:
@@ -176,7 +176,7 @@
         write(repo)
         return True
     finally:
-        w.release()
+        lock.release()
 
 def updatefromremote(ui, repo, remote, path):
     ui.debug("checking for updated bookmarks\n")
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -279,7 +279,7 @@
             if self.dir_:
                 self.rmtree(self.dir_, True)
 
-    srclock = destlock = dircleanup = None
+    srclock = destwlock = destlock = dircleanup = None
     try:
         abspath = origsource
         if islocal(origsource):
@@ -325,6 +325,11 @@
             # we need to re-init the repo after manually copying the data
             # into it
             destrepo = repository(remoteui(ui, peeropts), dest)
+            # we need full recursive locking of the new repo instance
+            destwlock = destrepo.wlock()
+            if destlock:
+                destlock.release() # a little race condition - but no deadlock
+            destlock = destrepo.lock()
             srcrepo.hook('outgoing', source='clone',
                           node=node.hex(node.nullid))
         else:
@@ -401,7 +406,7 @@
 
         return srcrepo, destrepo
     finally:
-        release(srclock, destlock)
+        release(srclock, destlock, destwlock)
         if dircleanup is not None:
             dircleanup.cleanup()
 


More information about the Mercurial-devel mailing list