summaryrefslogtreecommitdiffstats
path: root/subcmds/branches.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/branches.py')
-rw-r--r--subcmds/branches.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/subcmds/branches.py b/subcmds/branches.py
index fb60d7de..6d975ed4 100644
--- a/subcmds/branches.py
+++ b/subcmds/branches.py
@@ -1,5 +1,3 @@
1# -*- coding:utf-8 -*-
2#
3# Copyright (C) 2009 The Android Open Source Project 1# Copyright (C) 2009 The Android Open Source Project
4# 2#
5# Licensed under the Apache License, Version 2.0 (the "License"); 3# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,18 +12,21 @@
14# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
15# limitations under the License. 13# limitations under the License.
16 14
17from __future__ import print_function 15import itertools
18import sys 16import sys
17
19from color import Coloring 18from color import Coloring
20from command import Command 19from command import Command, DEFAULT_LOCAL_JOBS
20
21 21
22class BranchColoring(Coloring): 22class BranchColoring(Coloring):
23 def __init__(self, config): 23 def __init__(self, config):
24 Coloring.__init__(self, config, 'branch') 24 Coloring.__init__(self, config, 'branch')
25 self.current = self.printer('current', fg='green') 25 self.current = self.printer('current', fg='green')
26 self.local = self.printer('local') 26 self.local = self.printer('local')
27 self.notinproject = self.printer('notinproject', fg='red') 27 self.notinproject = self.printer('notinproject', fg='red')
28 28
29
29class BranchInfo(object): 30class BranchInfo(object):
30 def __init__(self, name): 31 def __init__(self, name):
31 self.name = name 32 self.name = name
@@ -61,7 +62,7 @@ class BranchInfo(object):
61 62
62 63
63class Branches(Command): 64class Branches(Command):
64 common = True 65 COMMON = True
65 helpSummary = "View current topic branches" 66 helpSummary = "View current topic branches"
66 helpUsage = """ 67 helpUsage = """
67%prog [<project>...] 68%prog [<project>...]
@@ -94,6 +95,7 @@ the branch appears in, or does not appear in. If no project list
94is shown, then the branch appears in all projects. 95is shown, then the branch appears in all projects.
95 96
96""" 97"""
98 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
97 99
98 def Execute(self, opt, args): 100 def Execute(self, opt, args):
99 projects = self.GetProjects(args) 101 projects = self.GetProjects(args)
@@ -101,14 +103,19 @@ is shown, then the branch appears in all projects.
101 all_branches = {} 103 all_branches = {}
102 project_cnt = len(projects) 104 project_cnt = len(projects)
103 105
104 for project in projects: 106 def _ProcessResults(_pool, _output, results):
105 for name, b in project.GetBranches().items(): 107 for name, b in itertools.chain.from_iterable(results):
106 b.project = project
107 if name not in all_branches: 108 if name not in all_branches:
108 all_branches[name] = BranchInfo(name) 109 all_branches[name] = BranchInfo(name)
109 all_branches[name].add(b) 110 all_branches[name].add(b)
110 111
111 names = list(sorted(all_branches)) 112 self.ExecuteInParallel(
113 opt.jobs,
114 expand_project_to_branches,
115 projects,
116 callback=_ProcessResults)
117
118 names = sorted(all_branches)
112 119
113 if not names: 120 if not names:
114 print(' (no branches)', file=sys.stderr) 121 print(' (no branches)', file=sys.stderr)
@@ -158,7 +165,7 @@ is shown, then the branch appears in all projects.
158 for b in i.projects: 165 for b in i.projects:
159 have.add(b.project) 166 have.add(b.project)
160 for p in projects: 167 for p in projects:
161 if not p in have: 168 if p not in have:
162 paths.append(p.relpath) 169 paths.append(p.relpath)
163 170
164 s = ' %s %s' % (in_type, ', '.join(paths)) 171 s = ' %s %s' % (in_type, ', '.join(paths))
@@ -170,11 +177,27 @@ is shown, then the branch appears in all projects.
170 fmt = out.current if i.IsCurrent else out.write 177 fmt = out.current if i.IsCurrent else out.write
171 for p in paths: 178 for p in paths:
172 out.nl() 179 out.nl()
173 fmt(width*' ' + ' %s' % p) 180 fmt(width * ' ' + ' %s' % p)
174 fmt = out.write 181 fmt = out.write
175 for p in non_cur_paths: 182 for p in non_cur_paths:
176 out.nl() 183 out.nl()
177 fmt(width*' ' + ' %s' % p) 184 fmt(width * ' ' + ' %s' % p)
178 else: 185 else:
179 out.write(' in all projects') 186 out.write(' in all projects')
180 out.nl() 187 out.nl()
188
189
190def expand_project_to_branches(project):
191 """Expands a project into a list of branch names & associated information.
192
193 Args:
194 project: project.Project
195
196 Returns:
197 List[Tuple[str, git_config.Branch]]
198 """
199 branches = []
200 for name, b in project.GetBranches().items():
201 b.project = project
202 branches.append((name, b))
203 return branches