changeset 51574:a0ef462cf1a4

branchcache: filter obsolete revisions sooner Since we won't do anything with the obsolete revisions, we can just ignore them sooner.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 06 Mar 2024 15:54:22 +0100
parents f85f23f1479b
children 50850689d3c0
files mercurial/branchmap.py
diffstat 1 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Thu Mar 07 10:55:22 2024 +0100
+++ b/mercurial/branchmap.py	Wed Mar 06 15:54:22 2024 +0100
@@ -284,16 +284,22 @@
         """
         starttime = util.timer()
         cl = repo.changelog
+        # Faster than using ctx.obsolete()
+        obsrevs = obsolete.getrevs(repo, b'obsolete')
         # collect new branch entries
         newbranches = {}
         getbranchinfo = repo.revbranchcache().branchinfo
         max_rev = -1
         for r in revgen:
+            max_rev = max(max_rev, r)
+            if r in obsrevs:
+                # We ignore obsolete changesets as they shouldn't be
+                # considered heads.
+                continue
             branch, closesbranch = getbranchinfo(r)
             newbranches.setdefault(branch, []).append(r)
             if closesbranch:
                 self._closednodes.add(cl.node(r))
-            max_rev = max(max_rev, r)
         if max_rev < 0:
             msg = "running branchcache.update without revision to update"
             raise error.ProgrammingError(msg)
@@ -306,9 +312,6 @@
         # use the faster unfiltered parent accessor.
         parentrevs = repo.unfiltered().changelog.parentrevs
 
-        # Faster than using ctx.obsolete()
-        obsrevs = obsolete.getrevs(repo, b'obsolete')
-
         for branch, newheadrevs in newbranches.items():
             # For every branch, compute the new branchheads.
             # A branchhead is a revision such that no descendant is on
@@ -349,11 +352,6 @@
             bheadset = {cl.rev(node) for node in bheads}
             uncertain = set()
             for newrev in sorted(newheadrevs):
-                if newrev in obsrevs:
-                    # We ignore obsolete changesets as they shouldn't be
-                    # considered heads.
-                    continue
-
                 if not bheadset:
                     bheadset.add(newrev)
                     continue