From b56a43a9064c35e81be989f5e86a19d9159d5edf Mon Sep 17 00:00:00 2001 From: Daniel Bratell Date: Thu, 6 Sep 2018 15:49:03 +0000 Subject: [PATCH] Read the git config only once when doing a git cl issue -r lookup Running git cl issue -r in a tree with dozens/hundreds of branches could be a bit slow since the code parsed .git/config twice per local branch. By parsing it only once and then looking things up in a hashtable it becomes much faster. (For my local tree with 700 branches 13 seconds became 0.3 seconds) Bug: 880734 Change-Id: I67f45de32fb7f2cc5960174e59f3476ef3021a3a Reviewed-on: https://chromium-review.googlesource.com/1206352 Commit-Queue: Andrii Shyshkalov Reviewed-by: Andrii Shyshkalov --- git_cl.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index 500641ecb..1204fed50 100755 --- a/git_cl.py +++ b/git_cl.py @@ -4608,9 +4608,20 @@ def CMDissue(parser, args): '--format=%(refname)']).splitlines() # Reverse issue lookup. issue_branch_map = {} + + git_config = {} + for config in RunGit(['config', '--get-regexp', + r'branch\..*issue']).splitlines(): + name, _space, val = config.partition(' ') + git_config[name] = val + for branch in branches: - cl = Changelist(branchref=branch) - issue_branch_map.setdefault(cl.GetIssue(), []).append(branch) + for cls in _CODEREVIEW_IMPLEMENTATIONS.values(): + config_key = _git_branch_config_key(ShortBranchName(branch), + cls.IssueConfigKey()) + issue = git_config.get(config_key) + if issue: + issue_branch_map.setdefault(int(issue), []).append(branch) if not args: args = sorted(issue_branch_map.iterkeys()) result = {}