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.
hg-reviewers |
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.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/discovery.py (14 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Pulkit Goyal | Mar 17 2019, 11:43 AM |
for n in outgoing.missing: | for n in outgoing.missing: | ||||
ctx = repo[n] | ctx = repo[n] | ||||
missingctx.add(ctx) | missingctx.add(ctx) | ||||
branches.add(ctx.branch()) | branches.add(ctx.branch()) | ||||
with remote.commandexecutor() as e: | with remote.commandexecutor() as e: | ||||
remotemap = e.callcommand('branchmap', {}).result() | remotemap = e.callcommand('branchmap', {}).result() | ||||
remotebranches = set(remotemap) | # A. register remote heads of branches which are in outgoing set | ||||
# A. register remote heads | |||||
for branch, heads in remotemap.iteritems(): | 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 = [] | known = [] | ||||
unsynced = [] | unsynced = [] | ||||
knownnode = cl.hasnode # do not use nodemap until it is filtered | knownnode = cl.hasnode # do not use nodemap until it is filtered | ||||
for h in heads: | for h in heads: | ||||
if knownnode(h): | if knownnode(h): | ||||
known.append(h) | known.append(h) | ||||
else: | else: | ||||
unsynced.append(h) | unsynced.append(h) | ||||
headssum[branch] = (known, list(known), unsynced) | headssum[branch] = (known, list(known), unsynced) | ||||
# B. add new branch data | # B. add new branch data | ||||
for branch in branches: | for branch in branches: | ||||
if branch not in headssum: | if branch not in headssum: | ||||
headssum[branch] = (None, [], []) | headssum[branch] = (None, [], []) | ||||
# C drop data about untouched branches: | # C. Update newmap with outgoing changes. | ||||
for branch in remotebranches - branches: | |||||
del headssum[branch] | |||||
# D. Update newmap with outgoing changes. | |||||
# This will possibly add new heads and remove existing ones. | # This will possibly add new heads and remove existing ones. | ||||
newmap = branchmap.remotebranchcache((branch, heads[1]) | newmap = branchmap.remotebranchcache((branch, heads[1]) | ||||
for branch, heads in headssum.iteritems() | for branch, heads in headssum.iteritems() | ||||
if heads[0] is not None) | if heads[0] is not None) | ||||
newmap.update(repo, (ctx.rev() for ctx in missingctx)) | newmap.update(repo, (ctx.rev() for ctx in missingctx)) | ||||
for branch, newheads in newmap.iteritems(): | for branch, newheads in newmap.iteritems(): | ||||
headssum[branch][1][:] = newheads | headssum[branch][1][:] = newheads | ||||
for branch, items in headssum.iteritems(): | for branch, items in headssum.iteritems(): |