Patchwork [04,of,11] phases: extract the core of boundary retraction in '_retractboundary'

login
register
mail settings
Submitter Boris Feld
Date July 14, 2017, 1:25 p.m.
Message ID <2a23f55b1b3487c7d43c.1500038738@FB>
Download mbox | patch
Permalink /patch/22321/
State Accepted
Headers show

Comments

Boris Feld - July 14, 2017, 1:25 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499723416 -7200
#      Mon Jul 10 23:50:16 2017 +0200
# Node ID 2a23f55b1b3487c7d43c0709efa900c01235b3cf
# Parent  d578e17d880990375cf64d4c026e927987211fe7
# EXP-Topic tr.changes.phases
phases: extract the core of boundary retraction in '_retractboundary'

At the moment the 'retractboundary' function is called for multiple reasons:

First, actually retracting boundaries. There are only two cases for theses:
'hg phase --force' and 'hg qimport'. This will need extra graph computation to
retrieve the phase changes.

Second, setting the phases of newly added changesets. In this case we already
know all the affected nodes and we just needs to register different
information (old phase is None).

Third, when reducing the set of roots when advancing phase. The phase are
already properly tracked so we do not needs anything else in this case.

To deal with this difference in phase tracking, we extract the core logic into
a private method that all three cases can use.

Patch

diff -r d578e17d8809 -r 2a23f55b1b34 mercurial/phases.py
--- a/mercurial/phases.py	Tue Jul 11 02:39:52 2017 +0200
+++ b/mercurial/phases.py	Mon Jul 10 23:50:16 2017 +0200
@@ -331,10 +331,14 @@ 
                 delroots.extend(olds - roots)
         # declare deleted root in the target phase
         if targetphase != 0:
-            self.retractboundary(repo, tr, targetphase, delroots)
+            self._retractboundary(repo, tr, targetphase, delroots)
         repo.invalidatevolatilesets()
 
     def retractboundary(self, repo, tr, targetphase, nodes):
+        self._retractboundary(repo, tr, targetphase, nodes)
+        repo.invalidatevolatilesets()
+
+    def _retractboundary(self, repo, tr, targetphase, nodes):
         # Be careful to preserve shallow-copied values: do not update
         # phaseroots values, replace them.
 
@@ -343,6 +347,7 @@ 
         newroots = [n for n in nodes
                     if self.phase(repo, repo[n].rev()) < targetphase]
         if newroots:
+
             if nullid in newroots:
                 raise error.Abort(_('cannot change null revision phase'))
             currentroots = currentroots.copy()
@@ -360,7 +365,6 @@ 
             finalroots.update(ctx.node() for ctx in updatedroots)
 
             self._updateroots(targetphase, finalroots, tr)
-        repo.invalidatevolatilesets()
 
     def filterunknown(self, repo):
         """remove unknown nodes from the phase boundary