Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: git_cl.py

Issue 1991563005: Add "archive" command to git_cl.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: use default sort() comparator Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld and Gerrit.""" 8 """A git-command for integrating reviews on Rietveld and Gerrit."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 2929 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 # Silence upload.py otherwise it becomes unwieldly. 2940 # Silence upload.py otherwise it becomes unwieldly.
2941 upload.verbosity = 0 2941 upload.verbosity = 0
2942 2942
2943 if fine_grained: 2943 if fine_grained:
2944 # Process one branch synchronously to work through authentication, then 2944 # Process one branch synchronously to work through authentication, then
2945 # spawn processes to process all the other branches in parallel. 2945 # spawn processes to process all the other branches in parallel.
2946 if changes: 2946 if changes:
2947 fetch = lambda cl: (cl, cl.GetStatus()) 2947 fetch = lambda cl: (cl, cl.GetStatus())
2948 yield fetch(changes[0]) 2948 yield fetch(changes[0])
2949 2949
2950 if len(changes) == 0:
M-A Ruel 2016/06/03 13:06:39 if not changes:
Kevin M 2016/06/03 22:34:00 Done.
2951 # Exit early if there was only one branch to fetch.
2952 return
2953
2950 changes_to_fetch = changes[1:] 2954 changes_to_fetch = changes[1:]
2951 pool = ThreadPool( 2955 pool = ThreadPool(
2952 min(max_processes, len(changes_to_fetch)) 2956 min(max_processes, len(changes_to_fetch))
2953 if max_processes is not None 2957 if max_processes is not None
2954 else len(changes_to_fetch)) 2958 else len(changes_to_fetch))
2955 2959
2956 fetched_cls = set() 2960 fetched_cls = set()
2957 it = pool.imap_unordered(fetch, changes_to_fetch).__iter__() 2961 it = pool.imap_unordered(fetch, changes_to_fetch).__iter__()
2958 while True: 2962 while True:
2959 try: 2963 try:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 RunGit(['checkout', '-q', root_branch]) 3069 RunGit(['checkout', '-q', root_branch])
3066 3070
3067 print 3071 print
3068 print 'Upload complete for dependent branches!' 3072 print 'Upload complete for dependent branches!'
3069 for dependent_branch in dependents: 3073 for dependent_branch in dependents:
3070 upload_status = 'failed' if failures.get(dependent_branch) else 'succeeded' 3074 upload_status = 'failed' if failures.get(dependent_branch) else 'succeeded'
3071 print ' %s : %s' % (dependent_branch, upload_status) 3075 print ' %s : %s' % (dependent_branch, upload_status)
3072 print 3076 print
3073 3077
3074 return 0 3078 return 0
3075 3079
M-A Ruel 2016/06/03 13:06:39 2 empty lines between file level symbols
Kevin M 2016/06/03 22:34:00 Done.
3080 def CMDarchive(parser, args):
3081 """Archives and deletes branches associated with closed changelists."""
3082 parser.add_option(
3083 '-j', '--maxjobs', action='store', type=int,
3084 help='The maximum number of jobs to use when retrieving review status')
3085 parser.add_option(
3086 '-f', '--force', action='store_true',
3087 help='Bypasses the confirmation prompt.')
3088
3089 auth.add_auth_options(parser)
3090 options, args = parser.parse_args(args)
3091 if args:
3092 parser.error('Unsupported args: %s' % ' '.join(args))
3093 auth_config = auth.extract_auth_config_from_options(options)
3094
3095 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads'])
3096 if not branches:
3097 return 0
3098
3099 print 'Finding all branches associated with closed issues...'
3100 changes = [Changelist(branchref=b, auth_config=auth_config)
3101 for b in branches.splitlines()]
3102 alignment = max(5, max(len(c.GetBranch()) for c in changes))
3103 statuses = get_cl_statuses(changes,
3104 fine_grained=True,
3105 max_processes=options.maxjobs)
3106 proposal = [(cl.GetBranch(),
3107 'git-cl-archived-%s-%s' % (cl.GetIssue(), cl.GetBranch()))
3108 for cl, status in statuses
3109 if status == 'closed']
3110 proposal.sort()
3111
3112 if not proposal:
3113 print 'No branches with closed codereview issues found.'
3114 return 0
3115
3116 current_branch = GetCurrentBranch()
3117
3118 print '\nBranches with closed issues that will be archived:\n'
3119 print '%*s | %s' % (alignment, 'Branch name', 'Archival tag name')
3120 for next_item in proposal:
3121 print '%*s %s' % (alignment, next_item[0], next_item[1])
3122
3123 if any(branch == current_branch for branch, _ in proposal):
3124 print('You are currently on a branch \'%s\' which is associated with a '
3125 'closed codereview issue, so archive cannot proceed. Please '
3126 'checkout another branch and run this command again.' %
3127 current_branch)
3128 return 1
3129
3130 if not options.force:
3131 if ask_for_data('\nProceed with deletion (Y/N)? ').lower() != 'y':
3132 print 'Aborted.'
3133 return 1
3134
3135 for branch, tagname in proposal:
3136 RunGit(['tag', tagname, branch])
3137 RunGit(['branch', '-D', branch])
3138 print '\nJob\'s done!'
3139
3140 return 0
3076 3141
M-A Ruel 2016/06/03 13:06:39 2 lines between file level symbols
Kevin M 2016/06/03 22:34:00 Done.
3077 def CMDstatus(parser, args): 3142 def CMDstatus(parser, args):
3078 """Show status of changelists. 3143 """Show status of changelists.
3079 3144
3080 Colors are used to tell the state of the CL unless --fast is used: 3145 Colors are used to tell the state of the CL unless --fast is used:
3081 - Red not sent for review or broken 3146 - Red not sent for review or broken
3082 - Blue waiting for review 3147 - Blue waiting for review
3083 - Yellow waiting for you to reply to review 3148 - Yellow waiting for you to reply to review
3084 - Green LGTM'ed 3149 - Green LGTM'ed
3085 - Magenta in the commit queue 3150 - Magenta in the commit queue
3086 - Cyan was committed, branch can be deleted 3151 - Cyan was committed, branch can be deleted
(...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after
4887 if __name__ == '__main__': 4952 if __name__ == '__main__':
4888 # These affect sys.stdout so do it outside of main() to simplify mocks in 4953 # These affect sys.stdout so do it outside of main() to simplify mocks in
4889 # unit testing. 4954 # unit testing.
4890 fix_encoding.fix_encoding() 4955 fix_encoding.fix_encoding()
4891 setup_color.init() 4956 setup_color.init()
4892 try: 4957 try:
4893 sys.exit(main(sys.argv[1:])) 4958 sys.exit(main(sys.argv[1:]))
4894 except KeyboardInterrupt: 4959 except KeyboardInterrupt:
4895 sys.stderr.write('interrupted\n') 4960 sys.stderr.write('interrupted\n')
4896 sys.exit(1) 4961 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698