discovery: prevent deleting items from a dictionary
authorPulkit Goyal <pulkit@yandex-team.ru>
Sun, 17 Mar 2019 18:43:27 +0300
changeset 42028 0cc9d7918754
parent 42027 d36a7da96a5a
child 42029 19ccc6788a27
discovery: prevent deleting items from a dictionary Removing elements from Python dictionary is expensive. So let's prevent adding them instead. I added a newline to make code look a bit better. Differential Revision: https://phab.mercurial-scm.org/D6146
mercurial/discovery.py
--- a/mercurial/discovery.py	Sun Mar 17 18:34:28 2019 +0300
+++ b/mercurial/discovery.py	Sun Mar 17 18:43:27 2019 +0300
@@ -212,10 +212,11 @@
     with remote.commandexecutor() as e:
         remotemap = e.callcommand('branchmap', {}).result()
 
-    remotebranches = set(remotemap)
-
-    # A. register remote heads
+    # A. register remote heads of branches which are in outgoing set
     for branch, heads in remotemap.iteritems():
+        # don't add head info about branches which we don't have locally
+        if branch not in branches:
+            continue
         known = []
         unsynced = []
         knownnode = cl.hasnode # do not use nodemap until it is filtered
@@ -225,16 +226,13 @@
             else:
                 unsynced.append(h)
         headssum[branch] = (known, list(known), unsynced)
+
     # B. add new branch data
     for branch in branches:
         if branch not in headssum:
             headssum[branch] = (None, [], [])
 
-    # C drop data about untouched branches:
-    for branch in remotebranches - branches:
-        del headssum[branch]
-
-    # D. Update newmap with outgoing changes.
+    # C. Update newmap with outgoing changes.
     # This will possibly add new heads and remove existing ones.
     newmap = branchmap.remotebranchcache((branch, heads[1])
                                  for branch, heads in headssum.iteritems()