D3671: advanceboundary: add dryrun parameter

khanchi97 (Sushil khanchi) phabricator at mercurial-scm.org
Wed May 30 09:27:51 UTC 2018


khanchi97 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Added logic to find those csets whose phase will be changed (when
  running without --dryrun) while advancing boundary. And make it return
  rejected and changed csets.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3671

AFFECTED FILES
  mercurial/phases.py

CHANGE DETAILS

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -352,7 +352,7 @@
                 _trackphasechange(phasetracking, rev, None, revphase)
         repo.invalidatevolatilesets()
 
-    def advanceboundary(self, repo, tr, targetphase, nodes):
+    def advanceboundary(self, repo, tr, targetphase, nodes, dryrun=None):
         """Set all 'nodes' to phase 'targetphase'
 
         Nodes with a phase lower than 'targetphase' are not affected.
@@ -366,6 +366,13 @@
 
         repo = repo.unfiltered()
 
+        rejected = list()
+        changes = [set(), set(), set()]
+        if dryrun:
+            getphase = repo._phasecache.phase
+            rejected = [repo[n].rev() for n in nodes
+                        if getphase(repo, repo[n].rev()) < targetphase]
+
         delroots = [] # set of root deleted by this path
         for phase in xrange(targetphase + 1, len(allphases)):
             # filter nodes that are not in a compatible phase already
@@ -377,20 +384,28 @@
             olds = self.phaseroots[phase]
 
             affected = repo.revs('%ln::%ln', olds, nodes)
-            for r in affected:
-                _trackphasechange(phasetracking, r, self.phase(repo, r),
-                                  targetphase)
+            if dryrun:
+                faffected = filter(lambda x: getphase(repo,
+                                                      repo[x].rev()) == phase,
+                                   affected)
+                changes[phase].update(faffected)
+            else:
+                for r in affected:
+                    _trackphasechange(phasetracking, r, self.phase(repo, r),
+                                      targetphase)
 
-            roots = set(ctx.node() for ctx in repo.set(
-                    'roots((%ln::) - %ld)', olds, affected))
-            if olds != roots:
-                self._updateroots(phase, roots, tr)
-                # some roots may need to be declared for lower phases
-                delroots.extend(olds - roots)
-        # declare deleted root in the target phase
-        if targetphase != 0:
-            self._retractboundary(repo, tr, targetphase, delroots)
-        repo.invalidatevolatilesets()
+                roots = set(ctx.node() for ctx in repo.set(
+                        'roots((%ln::) - %ld)', olds, affected))
+                if olds != roots:
+                    self._updateroots(phase, roots, tr)
+                    # some roots may need to be declared for lower phases
+                    delroots.extend(olds - roots)
+        if not dryrun:
+            # declare deleted root in the target phase
+            if targetphase != 0:
+                self._retractboundary(repo, tr, targetphase, delroots)
+            repo.invalidatevolatilesets()
+        return rejected, changes
 
     def retractboundary(self, repo, tr, targetphase, nodes):
         oldroots = self.phaseroots[:targetphase + 1]
@@ -478,16 +493,19 @@
         # (see branchmap one)
         self.invalidate()
 
-def advanceboundary(repo, tr, targetphase, nodes):
+def advanceboundary(repo, tr, targetphase, nodes, dryrun=None):
     """Add nodes to a phase changing other nodes phases if necessary.
 
     This function move boundary *forward* this means that all nodes
     are set in the target phase or kept in a *lower* phase.
 
     Simplify boundary to contains phase roots only."""
     phcache = repo._phasecache.copy()
-    phcache.advanceboundary(repo, tr, targetphase, nodes)
-    repo._phasecache.replace(phcache)
+    rejected, changes = phcache.advanceboundary(repo, tr, targetphase, nodes,
+                                                dryrun=dryrun)
+    if not dryrun:
+        repo._phasecache.replace(phcache)
+    return rejected, changes
 
 def retractboundary(repo, tr, targetphase, nodes):
     """Set nodes back to a phase changing other nodes phases if



To: khanchi97, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list