changeset 51583:22cc679a7312

phases: move RemotePhasesSummary to revision number This continue our quest to align more logic on revision number instead of node-ids. The motivation is similar to the change to `new_heads` and `analyze_remote_phases` a few changeset earlier. Again, we take this as an opportunity to rename the class, and the attribute to the new naming scheme. This will highlight the need for code update for any code using it an expecting node-ids. Many of the rev-num → node-id conversion we had to introduce in the previous changesets can now be removed. More will be removed in the future as we continue to align code toward rev-num usage. time saved in the 100 milliseconds order of magnitude for the mozilla-try benchmark I have been using.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 05 Apr 2024 14:11:02 +0200
parents d8287e43540f
children 5b99b64328f2
files mercurial/exchange.py mercurial/phases.py
diffstat 2 files changed, 35 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exchange.py	Fri Apr 05 12:24:47 2024 +0200
+++ b/mercurial/exchange.py	Fri Apr 05 14:11:02 2024 +0200
@@ -622,6 +622,7 @@
     (computed for both success and failure case for changesets push)"""
     outgoing = pushop.outgoing
     unfi = pushop.repo.unfiltered()
+    to_rev = unfi.changelog.index.rev
     remotephases = listkeys(pushop.remote, b'phases')
 
     if (
@@ -643,15 +644,19 @@
         pushop.fallbackoutdatedphases = []
         return
 
-    pushop.remotephases = phases.remotephasessummary(
-        pushop.repo, pushop.fallbackheads, remotephases
+    fallbackheads_rev = [to_rev(n) for n in pushop.fallbackheads]
+
+    pushop.remotephases = phases.RemotePhasesSummary(
+        pushop.repo,
+        fallbackheads_rev,
+        remotephases,
     )
-    droots = pushop.remotephases.draftroots
+    droots = pushop.remotephases.draft_roots
 
     extracond = b''
     if not pushop.remotephases.publishing:
         extracond = b' and public()'
-    revset = b'heads((%%ln::%%ln) %s)' % extracond
+    revset = b'heads((%%ld::%%ln) %s)' % extracond
     # Get the list of all revs draft on remote by public here.
     # XXX Beware that revset break if droots is not strictly
     # XXX root we may want to ensure it is but it is costly
@@ -659,7 +664,7 @@
     if not pushop.remotephases.publishing and pushop.publish:
         future = list(
             unfi.set(
-                b'%ln and (not public() or %ln::)', pushop.futureheads, droots
+                b'%ln and (not public() or %ld::)', pushop.futureheads, droots
             )
         )
     elif not outgoing.missing:
@@ -670,9 +675,9 @@
         # should not be necessary for publishing server, but because of an
         # issue fixed in xxxxx we have to do it anyway.
         fdroots = list(
-            unfi.set(b'roots(%ln  + %ln::)', outgoing.missing, droots)
+            unfi.set(b'roots(%ln  + %ld::)', outgoing.missing, droots)
         )
-        fdroots = [f.node() for f in fdroots]
+        fdroots = [f.rev() for f in fdroots]
         future = list(unfi.set(revset, fdroots, pushop.futureheads))
     pushop.outdatedphases = future
     pushop.fallbackoutdatedphases = fallback
@@ -903,8 +908,13 @@
     if pushop.remotephases is not None and hasphaseheads:
         # check that the remote phase has not changed
         checks = {p: [] for p in phases.allphases}
-        checks[phases.public].extend(pushop.remotephases.publicheads)
-        checks[phases.draft].extend(pushop.remotephases.draftroots)
+        to_node = pushop.repo.unfiltered().changelog.node
+        checks[phases.public].extend(
+            to_node(r) for r in pushop.remotephases.public_heads
+        )
+        checks[phases.draft].extend(
+            to_node(r) for r in pushop.remotephases.draft_roots
+        )
         if any(checks.values()):
             for phase in checks:
                 checks[phase].sort()
--- a/mercurial/phases.py	Fri Apr 05 12:24:47 2024 +0200
+++ b/mercurial/phases.py	Fri Apr 05 14:11:02 2024 +0200
@@ -1132,30 +1132,32 @@
     return public_heads, draft_roots
 
 
-class remotephasessummary:
+class RemotePhasesSummary:
     """summarize phase information on the remote side
 
     :publishing: True is the remote is publishing
-    :publicheads: list of remote public phase heads (nodes)
-    :draftheads: list of remote draft phase heads (nodes)
-    :draftroots: list of remote draft phase root (nodes)
+    :public_heads: list of remote public phase heads (revs)
+    :draft_heads: list of remote draft phase heads (revs)
+    :draft_roots: list of remote draft phase root (revs)
     """
 
-    def __init__(self, repo, remotesubset, remoteroots):
+    def __init__(
+        self,
+        repo,
+        remote_subset: Collection[int],
+        remote_roots: Dict[bytes, bytes],
+    ):
         unfi = repo.unfiltered()
-        to_rev = unfi.changelog.index.rev
-        to_node = unfi.changelog.node
-        self._allremoteroots = remoteroots
+        self._allremoteroots: Dict[bytes, bytes] = remote_roots
 
-        self.publishing = remoteroots.get(b'publishing', False)
+        self.publishing: bool = bool(remote_roots.get(b'publishing', False))
 
-        remote_subset = [to_rev(n) for n in remotesubset]
-        heads, roots = analyze_remote_phases(repo, remote_subset, remoteroots)
-        self.publicheads = [to_node(r) for r in heads]
-        self.draftroots = [to_node(r) for r in roots]
+        heads, roots = analyze_remote_phases(repo, remote_subset, remote_roots)
+        self.public_heads: Collection[int] = heads
+        self.draft_roots: Collection[int] = roots
         # Get the list of all "heads" revs draft on remote
         dheads = unfi.revs(b'heads(%ld::%ld)', roots, remote_subset)
-        self.draftheads = [to_node(r) for r in dheads]
+        self.draft_heads: Collection[int] = dheads
 
 
 def new_heads(