branchcache: filter obsolete revisions sooner
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 06 Mar 2024 15:54:22 +0100
changeset 51532 a0ef462cf1a4
parent 51531 f85f23f1479b
child 51533 50850689d3c0
branchcache: filter obsolete revisions sooner Since we won't do anything with the obsolete revisions, we can just ignore them sooner.
mercurial/branchmap.py
--- 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