Patchwork D3672: retractboundary: add dryrun parameter

login
register
mail settings
Submitter phabricator
Date June 3, 2018, 1:51 p.m.
Message ID <07138b1205b85ada7b738742ae0165c4@localhost.localdomain>
Download mbox | patch
Permalink /patch/31950/
State Not Applicable
Headers show

Comments

phabricator - June 3, 2018, 1:51 p.m.
khanchi97 updated this revision to Diff 8959.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3672?vs=8948&id=8959

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

AFFECTED FILES
  mercurial/phases.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -404,32 +404,46 @@ 
             repo.invalidatevolatilesets()
         return changes
 
-    def retractboundary(self, repo, tr, targetphase, nodes):
+    def retractboundary(self, repo, tr, targetphase, nodes, dryrun=None):
+        """If dryrun is True, no actions will be performed
+
+        Return a set of revs whose phase is changed or should be changed.
+        """
         oldroots = self.phaseroots[:targetphase + 1]
         if tr is None:
             phasetracking = None
         else:
             phasetracking = tr.changes.get('phases')
         repo = repo.unfiltered()
-        if (self._retractboundary(repo, tr, targetphase, nodes)
-            and phasetracking is not None):
+        changes = set() # set or revisions whose phase can be changed.
 
-            # find the affected revisions
-            new = self.phaseroots[targetphase]
-            old = oldroots[targetphase]
-            affected = set(repo.revs('(%ln::) - (%ln::)', new, old))
+        getphase = repo._phasecache.phase
+        nds = [n for n in nodes
+               if getphase(repo, repo[n].rev()) < targetphase]
+        targetphroots = oldroots[-1]
+        affected = set(repo.revs('(%ln::) - (%ln::)', nds, targetphroots))
+        changes.update(affected)
+        if not dryrun:
+            if (self._retractboundary(repo, tr, targetphase, nodes)
+                and phasetracking is not None):
 
-            # find the phase of the affected revision
-            for phase in xrange(targetphase, -1, -1):
-                if phase:
-                    roots = oldroots[phase]
-                    revs = set(repo.revs('%ln::%ld', roots, affected))
-                    affected -= revs
-                else: # public phase
-                    revs = affected
-                for r in revs:
-                    _trackphasechange(phasetracking, r, phase, targetphase)
-        repo.invalidatevolatilesets()
+                # find the affected revisions
+                new = self.phaseroots[targetphase]
+                old = oldroots[targetphase]
+                affected = set(repo.revs('(%ln::) - (%ln::)', new, old))
+
+                # find the phase of the affected revision
+                for phase in xrange(targetphase, -1, -1):
+                    if phase:
+                        roots = oldroots[phase]
+                        revs = set(repo.revs('%ln::%ld', roots, affected))
+                        affected -= revs
+                    else: # public phase
+                        revs = affected
+                    for r in revs:
+                        _trackphasechange(phasetracking, r, phase, targetphase)
+            repo.invalidatevolatilesets()
+        return changes
 
     def _retractboundary(self, repo, tr, targetphase, nodes):
         # Be careful to preserve shallow-copied values: do not update
@@ -509,17 +523,25 @@ 
         repo._phasecache.replace(phcache)
     return changes
 
-def retractboundary(repo, tr, targetphase, nodes):
+def retractboundary(repo, tr, targetphase, nodes, dryrun=None):
     """Set nodes back to a phase changing other nodes phases if
     necessary.
 
     This function move boundary *backward* this means that all nodes
     are set in the target phase or kept in a *higher* phase.
 
-    Simplify boundary to contains phase roots only."""
+    Simplify boundary to contains phase roots only.
+
+    If dryrun is True, no actions will be performed
+
+    Return a set of revs whose phase is changed or should be changed.
+    """
     phcache = repo._phasecache.copy()
-    phcache.retractboundary(repo, tr, targetphase, nodes)
-    repo._phasecache.replace(phcache)
+    changes = phcache.retractboundary(repo, tr, targetphase, nodes,
+                                      dryrun=dryrun)
+    if not dryrun:
+        repo._phasecache.replace(phcache)
+    return changes
 
 def registernew(repo, tr, targetphase, nodes):
     """register a new revision and its phase