changeset 1506:a55c691f4cc0

evolve: use repo._bookmarks.recordchange instead of repo._bookmarks.write We want to get rid of the api repo._bookmarks.write and this patch removes its use in evolve.py. Before this patch, we were using repo._bookmarks.write to save bookmarks change immediately instead of repo._bookmarks.recordchange that write change when transaction ends.
author Laurent Charignon <lcharignon@fb.com>
date Wed, 16 Sep 2015 16:50:06 -0700
parents 53a6dbc33e36
children 6f574c76c142
files hgext/evolve.py
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/evolve.py	Wed Sep 16 17:12:38 2015 -0700
+++ b/hgext/evolve.py	Wed Sep 16 16:50:06 2015 -0700
@@ -805,11 +805,15 @@
     nodeid was actually created. If created is False, nodeid
     references a changeset existing before the rewrite call.
     """
-    if True:
+    wlock = lock = tr = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        tr = repo.transaction('rewrite')
         if len(old.parents()) > 1: #XXX remove this unecessary limitation.
             raise error.Abort(_('cannot amend merge changesets'))
         base = old.p1()
-        updatebookmarks = _bookmarksupdater(repo, old.node())
+        updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
 
         # commit a new version of the old changeset, including the update
         # collect all files which might be affected
@@ -873,7 +877,10 @@
         created = len(repo) != revcount
         updatebookmarks(newid)
 
+        tr.close()
         return newid, created
+    finally:
+        lockmod.release(lock, wlock, tr)
 
 class MergeFailure(util.Abort):
     pass
@@ -972,13 +979,13 @@
         for book in destbookmarks: # restore bookmark that rebase move
             repo._bookmarks[book] = dest.node()
         if oldbookmarks or destbookmarks:
-            repo._bookmarks.write()
+            repo._bookmarks.recordchange(tr)
         tr.close()
     finally:
         tr.release()
     return nodenew
 
-def _bookmarksupdater(repo, oldid):
+def _bookmarksupdater(repo, oldid, tr):
     """Return a callable update(newid) updating the current bookmark
     and bookmarks bound to oldid to newid.
     """
@@ -990,7 +997,7 @@
                 repo._bookmarks[b] = newid
             dirty = True
         if dirty:
-            repo._bookmarks.write()
+            repo._bookmarks.recordchange(tr)
     return updatebookmarks
 
 ### bookmarks api compatibility layer ###
@@ -1782,9 +1789,9 @@
     if progresscb: progresscb()
     newid = tmpctx = None
     tmpctx = bumped
-    bmupdate = _bookmarksupdater(repo, bumped.node())
     # Basic check for common parent. Far too complicated and fragile
     tr = repo.transaction('bumped-stabilize')
+    bmupdate = _bookmarksupdater(repo, bumped.node(), tr)
     try:
         if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
             # Need to rebase the changeset at the right place
@@ -2338,7 +2345,7 @@
             # slower. The new forms makes as much sense and a much faster.
             for dest in ctx.ancestors():
                 if not dest.obsolete():
-                    updatebookmarks = _bookmarksupdater(repo, ctx.node())
+                    updatebookmarks = _bookmarksupdater(repo, ctx.node(), tr)
                     updatebookmarks(dest.node())
                     break
 
@@ -2523,7 +2530,6 @@
         if len(old.parents()) > 1:
             raise util.Abort(_("cannot uncommit merge changeset"))
         oldphase = old.phase()
-        updatebookmarks = _bookmarksupdater(repo, old.node())
 
 
         rev = None
@@ -2540,6 +2546,7 @@
 
         # Recommit the filtered changeset
         tr = repo.transaction('uncommit')
+        updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
         newid = None
         includeorexclude = opts.get('include') or opts.get('exclude')
         if (pats or includeorexclude or opts.get('all')):
@@ -2634,7 +2641,7 @@
         if len(ctx.parents()) > 1:
             raise util.Abort(_("cannot split merge commits"))
         prev = ctx.p1()
-        bmupdate = _bookmarksupdater(repo, ctx.node())
+        bmupdate = _bookmarksupdater(repo, ctx.node(), tr)
         bookactive = bmactive(repo)
         if bookactive is not None:
             repo.ui.status(_("(leaving bookmark %s)\n") % bmactive(repo))