Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 35785ebdf0443e4c86784f4c820b0a7c71ca9103..4c7cd93adcc1ff270c50f2d8059a269e147b9f35 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,68 @@ 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' % ' '.join(args)) |
| + 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(), |
| + 'git-cl-closed-%s-%s' % (cl.GetBranch(), cl.GetIssue())) |
| + for cl, status in statuses |
| + if status == 'closed'] |
| + |
| + if len(proposal) == 0: |
| + print 'No branches with closed codereview issues found.' |
| + return 0 |
| + |
| + current_branch = RunGit(['symbolic-ref', 'HEAD', '--short']).strip() |
|
tandrii(chromium)
2016/05/31 20:18:32
use existing func:
current_branch = GetCurrentBran
Kevin M
2016/05/31 20:26:35
Done.
|
| + print "Current branch: " + current_branch |
| + |
| + if any(branch == current_branch for branch, _ in proposal): |
|
tandrii(chromium)
2016/05/31 20:18:33
I'd print all the branches with closed issues firs
Kevin M
2016/05/31 20:26:35
Done.
|
| + print 'You are currently using a branch associated with a closed' |
|
tandrii(chromium)
2016/05/31 20:18:33
s/using a branch associated/on a branch %s associa
Kevin M
2016/05/31 20:26:35
Done.
|
| + print 'codereview issue, so cleanup cannot proceed. Please change to ' |
|
tandrii(chromium)
2016/05/31 20:18:33
use 1 print statement (basically, call) and don't
Kevin M
2016/05/31 20:26:35
Done.
|
| + print 'another branch and run \'git cl cleanup\' again.' |
| + return 1 |
| + |
| + print '\nBranches with closed issues that will be tagged and deleted:' |
| + print '%*s | %s' % (alignment, 'Branch name', 'Archival tag name') |
| + for next_item in proposal: |
| + print '%*s %s' % (alignment, next_item[0], next_item[1]) |
| + |
| + if not options.force: |
| + if ask_for_data('\nProceed with deletion (Y/N)? ').lower() != 'y': |
| + print 'Aborted.' |
| + return 1 |
| + |
| + for branch, tagname in proposal: |
| + RunGit(['tag', tagname, branch]) |
| + RunGit(['branch', '-D', branch]) |
| + print '\nJob\'s done!' |
| + |
| + return 0 |
| def CMDstatus(parser, args): |
| """Show status of changelists. |