branchmap: don't add branch entries if there are no heads
authorAnton Shestakov <av6@dwimlabs.net>
Sun, 06 Feb 2022 19:31:39 +0300
changeset 48732 8b393f40a5e6
parent 48731 ae27a0684e75
child 48733 02e9ad08999b
branchmap: don't add branch entries if there are no heads We definitely don't want any empty entries to be present in repo.branchmap() just for the sake of not breaking test-notify.t. No test changes required because the previous patch made notify extension to not raise any tracebacks in case of RepoLookupErrors. Differential Revision: https://phab.mercurial-scm.org/D12135
mercurial/branchmap.py
--- a/mercurial/branchmap.py	Sun Feb 06 19:14:51 2022 +0300
+++ b/mercurial/branchmap.py	Sun Feb 06 19:31:39 2022 +0300
@@ -519,7 +519,7 @@
             #   checks can be skipped. Otherwise, the ancestors of the
             #   "uncertain" set are removed from branchheads.
             #   This computation is heavy and avoided if at all possible.
-            bheads = self._entries.setdefault(branch, [])
+            bheads = self._entries.get(branch, [])
             bheadset = {cl.rev(node) for node in bheads}
             uncertain = set()
             for newrev in sorted(newheadrevs):
@@ -562,8 +562,8 @@
                     if floorrev <= max(uncertain):
                         ancestors = set(cl.ancestors(uncertain, floorrev))
                         bheadset -= ancestors
-            bheadrevs = sorted(bheadset)
-            self[branch] = [cl.node(rev) for rev in bheadrevs]
+            if bheadset:
+                self[branch] = [cl.node(rev) for rev in sorted(bheadset)]
             tiprev = max(newheadrevs)
             if tiprev > ntiprev:
                 ntiprev = tiprev