Don't shell out to git to resolve upstream branches unnecessarily

Even though we already know the parent is origin/main, every branch that
is parented to origin/main ends up shelling out to git in the upstream()
function, just to double-check that origin/main exists.

If the parent has already been registered, don't bother repeating the
work. This cuts out about half of the times that git map-branches shells
out to git and reduces it from 1.7s to 1.2s on my machine.

Change-Id: Ic5fdaaa5bc62ed8a3574f5a28f9f783093dacc2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5498460
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Auto-Submit: David Benjamin <davidben@chromium.org>
changes/60/5498460/2
David Benjamin 10 months ago committed by LUCI CQ
parent 2f0f9bc0bd
commit 54b27c0a13

@ -153,18 +153,17 @@ class BranchMapper(object):
if not branch_info:
continue
parent = branch_info.upstream
if self.__check_cycle(branch):
continue
parent = branch_info.upstream
if not self.__branches_info[parent]:
branch_upstream = upstream(branch)
# If git can't find the upstream, mark the upstream as gone.
if branch_upstream:
parent = branch_upstream
else:
self.__gone_branches.add(parent)
# A parent that isn't in the branches info is a root.
roots.add(parent)
# If the parent is not a known branch, it may be an upstream
# branch like origin/main or it may be gone. Determine which it
# is, but don't re-query the same parent multiple times.
if parent not in roots:
if not upstream(branch):
self.__gone_branches.add(parent)
roots.add(parent)
self.__parent_map[parent].append(branch)

Loading…
Cancel
Save