Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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: | |
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 3080 def CMDcleanup(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 | |
| 3086 parser.add_option( | |
| 3087 '-f', action='store_true', dest='force', default=False, | |
| 3088 help='Bypasses the confirmation prompt.') | |
| 3089 | |
| 3090 auth.add_auth_options(parser) | |
| 3091 options, args = parser.parse_args(args) | |
| 3092 if args: | |
| 3093 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.
| |
| 3094 auth_config = auth.extract_auth_config_from_options(options) | |
| 3095 | |
| 3096 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) | |
| 3097 if not branches: | |
| 3098 print 'No local branch found.' | |
| 3099 return 0 | |
| 3100 | |
| 3101 print 'Finding all branches associated with closed issues...' | |
| 3102 changes = [Changelist(branchref=b, auth_config=auth_config) | |
| 3103 for b in branches.splitlines()] | |
| 3104 alignment = max(5, max(len(c.GetBranch()) for c in changes)) | |
| 3105 statuses = get_cl_statuses(changes, | |
| 3106 fine_grained=True, | |
| 3107 max_processes=options.maxjobs) | |
| 3108 proposal = [(cl.GetBranch(), | |
| 3109 '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.
| |
| 3110 for cl, status in statuses | |
| 3111 if status == 'closed'] | |
| 3112 | |
| 3113 if len(proposal) == 0: | |
| 3114 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.
| |
| 3115 return 0 | |
| 3116 | |
| 3117 print '\nBranches with closed issues that will be tagged and deleted:' | |
| 3118 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.
| |
| 3119 for next_item in proposal: | |
| 3120 print '%*s %s' % (alignment, next_item[0], next_item[1]) | |
| 3121 | |
| 3122 prompt = None | |
| 3123 if not options.force: | |
| 3124 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.
| |
| 3125 if prompt == 'Y' or prompt == 'y' or options.force: | |
| 3126 for next_item in proposal: | |
| 3127 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.
| |
| 3128 RunGit(['tag', tagname, branch]) | |
| 3129 RunGit(['branch', '-D', branch]) | |
| 3130 print '\nJob\'s done!' | |
| 3131 else: | |
| 3132 print 'Aborted.' | |
| 3133 | |
| 3134 return 0 | |
| 3076 | 3135 |
| 3077 def CMDstatus(parser, args): | 3136 def CMDstatus(parser, args): |
| 3078 """Show status of changelists. | 3137 """Show status of changelists. |
| 3079 | 3138 |
| 3080 Colors are used to tell the state of the CL unless --fast is used: | 3139 Colors are used to tell the state of the CL unless --fast is used: |
| 3081 - Red not sent for review or broken | 3140 - Red not sent for review or broken |
| 3082 - Blue waiting for review | 3141 - Blue waiting for review |
| 3083 - Yellow waiting for you to reply to review | 3142 - Yellow waiting for you to reply to review |
| 3084 - Green LGTM'ed | 3143 - Green LGTM'ed |
| 3085 - Magenta in the commit queue | 3144 - Magenta in the commit queue |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4887 if __name__ == '__main__': | 4946 if __name__ == '__main__': |
| 4888 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4947 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 4889 # unit testing. | 4948 # unit testing. |
| 4890 fix_encoding.fix_encoding() | 4949 fix_encoding.fix_encoding() |
| 4891 setup_color.init() | 4950 setup_color.init() |
| 4892 try: | 4951 try: |
| 4893 sys.exit(main(sys.argv[1:])) | 4952 sys.exit(main(sys.argv[1:])) |
| 4894 except KeyboardInterrupt: | 4953 except KeyboardInterrupt: |
| 4895 sys.stderr.write('interrupted\n') | 4954 sys.stderr.write('interrupted\n') |
| 4896 sys.exit(1) | 4955 sys.exit(1) |
| OLD | NEW |