summaryrefslogtreecommitdiffstats
path: root/subcmds/prune.py
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-03-11 06:46:20 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-22 17:46:28 +0000
commitea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch)
treedc33ba0e56825b3e007d0589891756724725a465 /subcmds/prune.py
parent1604cf255f8c1786a23388db6d5277ac7949a24a (diff)
downloadgit-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught by flake8. Also check black formatting in run_tests (and CQ). Bug: b/267675342 Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'subcmds/prune.py')
-rw-r--r--subcmds/prune.py107
1 files changed, 60 insertions, 47 deletions
diff --git a/subcmds/prune.py b/subcmds/prune.py
index 251accaa..5a68c14a 100644
--- a/subcmds/prune.py
+++ b/subcmds/prune.py
@@ -19,63 +19,76 @@ from command import DEFAULT_LOCAL_JOBS, PagedCommand
19 19
20 20
21class Prune(PagedCommand): 21class Prune(PagedCommand):
22 COMMON = True 22 COMMON = True
23 helpSummary = "Prune (delete) already merged topics" 23 helpSummary = "Prune (delete) already merged topics"
24 helpUsage = """ 24 helpUsage = """
25%prog [<project>...] 25%prog [<project>...]
26""" 26"""
27 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS 27 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
28 28
29 def _ExecuteOne(self, project): 29 def _ExecuteOne(self, project):
30 """Process one project.""" 30 """Process one project."""
31 return project.PruneHeads() 31 return project.PruneHeads()
32 32
33 def Execute(self, opt, args): 33 def Execute(self, opt, args):
34 projects = self.GetProjects(args, all_manifests=not opt.this_manifest_only) 34 projects = self.GetProjects(
35 args, all_manifests=not opt.this_manifest_only
36 )
35 37
36 # NB: Should be able to refactor this module to display summary as results 38 # NB: Should be able to refactor this module to display summary as
37 # come back from children. 39 # results come back from children.
38 def _ProcessResults(_pool, _output, results): 40 def _ProcessResults(_pool, _output, results):
39 return list(itertools.chain.from_iterable(results)) 41 return list(itertools.chain.from_iterable(results))
40 42
41 all_branches = self.ExecuteInParallel( 43 all_branches = self.ExecuteInParallel(
42 opt.jobs, 44 opt.jobs,
43 self._ExecuteOne, 45 self._ExecuteOne,
44 projects, 46 projects,
45 callback=_ProcessResults, 47 callback=_ProcessResults,
46 ordered=True) 48 ordered=True,
49 )
47 50
48 if not all_branches: 51 if not all_branches:
49 return 52 return
50 53
51 class Report(Coloring): 54 class Report(Coloring):
52 def __init__(self, config): 55 def __init__(self, config):
53 Coloring.__init__(self, config, 'status') 56 Coloring.__init__(self, config, "status")
54 self.project = self.printer('header', attr='bold') 57 self.project = self.printer("header", attr="bold")
55 58
56 out = Report(all_branches[0].project.config) 59 out = Report(all_branches[0].project.config)
57 out.project('Pending Branches') 60 out.project("Pending Branches")
58 out.nl() 61 out.nl()
59 62
60 project = None 63 project = None
61 64
62 for branch in all_branches: 65 for branch in all_branches:
63 if project != branch.project: 66 if project != branch.project:
64 project = branch.project 67 project = branch.project
65 out.nl() 68 out.nl()
66 out.project('project %s/' % project.RelPath(local=opt.this_manifest_only)) 69 out.project(
67 out.nl() 70 "project %s/"
71 % project.RelPath(local=opt.this_manifest_only)
72 )
73 out.nl()
68 74
69 print('%s %-33s ' % ( 75 print(
70 branch.name == project.CurrentBranch and '*' or ' ', 76 "%s %-33s "
71 branch.name), end='') 77 % (
78 branch.name == project.CurrentBranch and "*" or " ",
79 branch.name,
80 ),
81 end="",
82 )
72 83
73 if not branch.base_exists: 84 if not branch.base_exists:
74 print('(ignoring: tracking branch is gone: %s)' % (branch.base,)) 85 print(
75 else: 86 "(ignoring: tracking branch is gone: %s)" % (branch.base,)
76 commits = branch.commits 87 )
77 date = branch.date 88 else:
78 print('(%2d commit%s, %s)' % ( 89 commits = branch.commits
79 len(commits), 90 date = branch.date
80 len(commits) != 1 and 's' or ' ', 91 print(
81 date)) 92 "(%2d commit%s, %s)"
93 % (len(commits), len(commits) != 1 and "s" or " ", date)
94 )