bundle2: only grab a transaction when 'phase-heads' affect the repository
authorBoris Feld <boris.feld@octobus.net>
Wed, 20 Sep 2017 18:29:10 +0200
changeset 34328 4ef472b975ff
parent 34327 12c42bcd4133
child 34329 10e162bb9bf5
bundle2: only grab a transaction when 'phase-heads' affect the repository The next patch will use the 'phase-heads' part to exchange phase data relevant to the pulled set. 'handlephases' currently acquires a transaction even in case of no-op pull, which would results in an empty transaction and messing with the existing journal. Pass the transaction fetcher to updatephases so it can fetch it if necessary.
mercurial/bundle2.py
mercurial/phases.py
--- a/mercurial/bundle2.py	Tue Sep 19 22:23:41 2017 +0200
+++ b/mercurial/bundle2.py	Wed Sep 20 18:29:10 2017 +0200
@@ -1840,7 +1840,7 @@
 def handlephases(op, inpart):
     """apply phases from bundle part to repo"""
     headsbyphase = phases.binarydecode(inpart)
-    phases.updatephases(op.repo.unfiltered(), op.gettransaction(), headsbyphase)
+    phases.updatephases(op.repo.unfiltered(), op.gettransaction, headsbyphase)
     op.records.add('phase-heads', {})
 
 @parthandler('reply:pushkey', ('return', 'in-reply-to'))
--- a/mercurial/phases.py	Tue Sep 19 22:23:41 2017 +0200
+++ b/mercurial/phases.py	Wed Sep 20 18:29:10 2017 +0200
@@ -558,11 +558,18 @@
         headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)]
     return headsbyphase
 
-def updatephases(repo, tr, headsbyphase):
+def updatephases(repo, trgetter, headsbyphase):
     """Updates the repo with the given phase heads"""
     # Now advance phase boundaries of all but secret phase
+    #
+    # run the update (and fetch transaction) only if there are actually things
+    # to update. This avoid creating empty transaction during no-op operation.
+
     for phase in allphases[:-1]:
-        advanceboundary(repo, tr, phase, headsbyphase[phase])
+        revset = '%%ln - %s()' % phasenames[phase]
+        heads = [c.node() for c in repo.set(revset, headsbyphase[phase])]
+        if heads:
+            advanceboundary(repo, trgetter(), phase, heads)
 
 def analyzeremotephases(repo, subset, roots):
     """Compute phases heads and root in a subset of node from root dict