[PATCH 2 of 2 evolve-ext] evolve: use repo._bookmarks.recordchange instead of repo._bookmarks.write

Laurent Charignon lcharignon at fb.com
Thu Sep 17 20:39:50 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1442447406 25200
#      Wed Sep 16 16:50:06 2015 -0700
# Node ID 3c275631d09518c1c167500bcb5fa81fca375dcd
# Parent  d525123c5a12f7e60eaaf24ec5ab00a43675fef4
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.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -805,11 +805,15 @@ def rewrite(repo, old, updates, head, ne
     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 @@ def rewrite(repo, old, updates, head, ne
         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 @@ def relocate(repo, orig, dest, keepbranc
         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 @@ def _bookmarksupdater(repo, oldid):
                 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 @@ def _solvebumped(ui, repo, bumped, dryru
     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 @@ def cmdprune(ui, repo, *revs, **opts):
             # 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 @@ def uncommit(ui, repo, *pats, **opts):
         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 @@ def uncommit(ui, repo, *pats, **opts):
 
         # 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 @@ def cmdsplit(ui, repo, *revs, **opts):
         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))


More information about the Mercurial-devel mailing list