Patchwork [5,of,7,bundle2] bundle2: only grab a transaction when 'phase-heads' affect the repository

login
register
mail settings
Submitter Boris Feld
Date Sept. 28, 2017, 5:08 a.m.
Message ID <7079b5aaf647e041e2dc.1506575320@FB>
Download mbox | patch
Permalink /patch/24197/
State Accepted
Headers show

Comments

Boris Feld - Sept. 28, 2017, 5:08 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1505924950 -7200
#      Wed Sep 20 18:29:10 2017 +0200
# Node ID 7079b5aaf647e041e2dc8bc6526b9c7a2efbdc71
# Parent  6bd13c121a92e5871f0874dc4d6db4ea9d2406f9
# EXP-Topic b2.phases
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.

Patch

diff -r 6bd13c121a92 -r 7079b5aaf647 mercurial/bundle2.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'))
diff -r 6bd13c121a92 -r 7079b5aaf647 mercurial/phases.py
--- 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