Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 35785ebdf0443e4c86784f4c820b0a7c71ca9103..f0097526ed1f8a063073743de2d8dd956ae32e34 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -2947,6 +2947,10 @@ def get_cl_statuses(changes, fine_grained, max_processes=None): |
| fetch = lambda cl: (cl, cl.GetStatus()) |
| yield fetch(changes[0]) |
| + if len(changes) == 0: |
| + # Exit early if there was only one branch to fetch. |
| + return |
| + |
| changes_to_fetch = changes[1:] |
| pool = ThreadPool( |
| min(max_processes, len(changes_to_fetch)) |
| @@ -3073,6 +3077,61 @@ def upload_branch_deps(cl, args): |
| return 0 |
| +def CMDcleanup(parser, args): |
| + """Archives and deletes branches associated with closed changelists.""" |
| + parser.add_option( |
| + '-j', '--maxjobs', action='store', type=int, |
| + help='The maximum number of jobs to use when retrieving review status') |
| + |
| + parser.add_option( |
| + '-f', action='store_true', dest='force', default=False, |
| + help='Bypasses the confirmation prompt.') |
| + |
| + auth.add_auth_options(parser) |
| + options, args = parser.parse_args(args) |
| + if args: |
| + parser.error('Unsupported args: %s' % args) |
|
tandrii(chromium)
2016/05/31 18:46:16
parser.error('Unsupported args: %s' % ' '.join(arg
Kevin M
2016/05/31 20:05:21
Done.
|
| + auth_config = auth.extract_auth_config_from_options(options) |
| + |
| + branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) |
| + if not branches: |
| + print 'No local branch found.' |
| + return 0 |
| + |
| + print 'Finding all branches associated with closed issues...' |
| + changes = [Changelist(branchref=b, auth_config=auth_config) |
| + for b in branches.splitlines()] |
| + alignment = max(5, max(len(c.GetBranch()) for c in changes)) |
| + statuses = get_cl_statuses(changes, |
| + fine_grained=True, |
| + max_processes=options.maxjobs) |
| + proposal = [(cl.GetBranch(), |
| + 'submitted-%s-%s' % (cl.GetBranch(), cl.GetIssue())) |
|
tandrii(chromium)
2016/05/31 18:46:16
WDYT about "git-cl-closed-%s-%s"?
This way it's mu
Kevin M
2016/05/31 20:05:21
Done.
|
| + for cl, status in statuses |
| + if status == 'closed'] |
| + |
| + if len(proposal) == 0: |
| + print 'No closed branches found.' |
|
tandrii(chromium)
2016/05/31 18:46:16
WDYT about 'No branches with closed codereview iss
Kevin M
2016/05/31 20:05:21
Done.
|
| + return 0 |
| + |
| + print '\nBranches with closed issues that will be tagged and deleted:' |
| + print "%*s | %s" % (alignment, "Branch name", "Archival tag name") |
|
tandrii(chromium)
2016/05/31 18:46:16
nits: single quotes (s/"/')
Kevin M
2016/05/31 20:05:21
Done.
|
| + for next_item in proposal: |
| + print '%*s %s' % (alignment, next_item[0], next_item[1]) |
| + |
| + prompt = None |
| + if not options.force: |
| + prompt = raw_input('\nProceed with deletion (Y/N)? ') |
|
tandrii(chromium)
2016/05/31 18:46:16
s/raw_input/ask_for_data
and how about exiting im
Kevin M
2016/05/31 20:05:21
That looks better, done.
|
| + if prompt == 'Y' or prompt == 'y' or options.force: |
| + for next_item in proposal: |
| + branch, tagname = next_item |
|
tandrii(chromium)
2016/05/31 18:46:16
combine this and above:
for branch, tagname in pro
Kevin M
2016/05/31 20:05:21
Done.
|
| + RunGit(['tag', tagname, branch]) |
| + RunGit(['branch', '-D', branch]) |
| + print '\nJob\'s done!' |
| + else: |
| + print 'Aborted.' |
| + |
| + return 0 |
| def CMDstatus(parser, args): |
| """Show status of changelists. |