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 <tandrii@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 500641e..1204fed 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -4608,9 +4608,20 @@
                        '--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 = {}