phases: leverage the collected information to record phase update
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 20 Feb 2024 23:46:21 +0100
changeset 51410 eababb7b4a82
parent 51409 2f39c7aeb549
child 51411 774e4eff6e47
phases: leverage the collected information to record phase update Since the lower level function already gather this information, we can directly use it. This comes with a small change to the test that are actually fixing them. The previous version over-reported some phase change that did not exists. In both case, we are force revision `1` to be secret and `0` remains draft`, the previous code wrongly reported `0` as moving to secret while it properly remained draft in the repository.
mercurial/phases.py
tests/test-phases-exchange.t
tests/test-phases.t
--- a/mercurial/phases.py	Wed Feb 21 10:41:09 2024 +0100
+++ b/mercurial/phases.py	Tue Feb 20 23:46:21 2024 +0100
@@ -645,11 +645,6 @@
         return changes
 
     def retractboundary(self, repo, tr, targetphase, nodes):
-        oldroots = {
-            phase: revs
-            for phase, revs in self._phaseroots.items()
-            if phase <= targetphase
-        }
         if tr is None:
             phasetracking = None
         else:
@@ -657,22 +652,8 @@
         repo = repo.unfiltered()
         retracted = self._retractboundary(repo, tr, targetphase, nodes)
         if retracted and phasetracking is not None:
-
-            # find the affected revisions
-            new = self._phaseroots[targetphase]
-            old = oldroots[targetphase]
-            affected = set(repo.revs(b'(%ld::) - (%ld::)', new, old))
-
-            # find the phase of the affected revision
-            for phase in range(targetphase, -1, -1):
-                if phase:
-                    roots = oldroots.get(phase, [])
-                    revs = set(repo.revs(b'%ld::%ld', roots, affected))
-                    affected -= revs
-                else:  # public phase
-                    revs = affected
-                for r in sorted(revs):
-                    _trackphasechange(phasetracking, r, phase, targetphase)
+            for r, old_phase in sorted(retracted.items()):
+                _trackphasechange(phasetracking, r, old_phase, targetphase)
         repo.invalidatevolatilesets()
 
     def _retractboundary(self, repo, tr, targetphase, nodes=None, revs=None):
--- a/tests/test-phases-exchange.t	Wed Feb 21 10:41:09 2024 +0100
+++ b/tests/test-phases-exchange.t	Tue Feb 20 23:46:21 2024 +0100
@@ -1595,7 +1595,6 @@
 trying to push a secret changeset doesn't confuse auto-publish
 
   $ hg phase --secret --force
-  test-debug-phase: move rev 0: 1 -> 2
   test-debug-phase: move rev 1: 1 -> 2
 
   $ hg push --config experimental.auto-publish=abort
--- a/tests/test-phases.t	Wed Feb 21 10:41:09 2024 +0100
+++ b/tests/test-phases.t	Tue Feb 20 23:46:21 2024 +0100
@@ -54,9 +54,7 @@
 Working directory phase is secret when its parent is secret.
 
   $ hg phase --force --secret .
-  test-debug-phase: move rev 0: 1 -> 2
   test-debug-phase: move rev 1: 1 -> 2
-  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:  draft -> secret
   test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:  draft -> secret
   $ hg log -r 'wdir()' -T '{phase}\n'
   secret