push: update bookmarks (on server) within a transaction
authorPierre-Yves David <pierre-yves.david@fb.com>
Sun, 28 Sep 2014 17:35:33 -0700
changeset 22667 3acc3f95548c
parent 22666 0f8120c1ecf5
child 22668 13e3f07d74a3
push: update bookmarks (on server) within a transaction A nice side effect is that bookmarks sent through bundle2 are updated within the same transaction as all other changes.
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Sun Sep 28 15:21:38 2014 -0700
+++ b/mercurial/bookmarks.py	Sun Sep 28 17:35:33 2014 -0700
@@ -7,7 +7,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import hex, bin
-from mercurial import encoding, error, util, obsolete
+from mercurial import encoding, error, util, obsolete, lock as lockmod
 import errno
 
 class bmstore(dict):
@@ -235,8 +235,11 @@
     return d
 
 def pushbookmark(repo, key, old, new):
-    w = repo.wlock()
+    w = l = tr = None
     try:
+        w = repo.wlock()
+        l = repo.lock()
+        tr = repo.transaction('bookmarks')
         marks = repo._bookmarks
         existing = hex(marks.get(key, ''))
         if existing != old and existing != new:
@@ -247,10 +250,11 @@
             if new not in repo:
                 return False
             marks[key] = repo[new].node()
-        marks.write()
+        marks.recordchange(tr)
+        tr.close()
         return True
     finally:
-        w.release()
+        lockmod.release(tr, l, w)
 
 def compare(repo, srcmarks, dstmarks,
             srchex=None, dsthex=None, targets=None):