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' % ' '.join(args)) | |
| 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 'git-cl-closed-%s-%s' % (cl.GetBranch(), cl.GetIssue())) | |
| 3110 for cl, status in statuses | |
| 3111 if status == 'closed'] | |
| 3112 | |
| 3113 if len(proposal) == 0: | |
| 3114 print 'No branches with closed codereview issues found.' | |
| 3115 return 0 | |
| 3116 | |
| 3117 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.
| |
| 3118 print "Current branch: " + current_branch | |
| 3119 | |
| 3120 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.
| |
| 3121 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.
| |
| 3122 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.
| |
| 3123 print 'another branch and run \'git cl cleanup\' again.' | |
| 3124 return 1 | |
| 3125 | |
| 3126 print '\nBranches with closed issues that will be tagged and deleted:' | |
| 3127 print '%*s | %s' % (alignment, 'Branch name', 'Archival tag name') | |
| 3128 for next_item in proposal: | |
| 3129 print '%*s %s' % (alignment, next_item[0], next_item[1]) | |
| 3130 | |
| 3131 if not options.force: | |
| 3132 if ask_for_data('\nProceed with deletion (Y/N)? ').lower() != 'y': | |
| 3133 print 'Aborted.' | |
| 3134 return 1 | |
| 3135 | |
| 3136 for branch, tagname in proposal: | |
| 3137 RunGit(['tag', tagname, branch]) | |
| 3138 RunGit(['branch', '-D', branch]) | |
| 3139 print '\nJob\'s done!' | |
| 3140 | |
| 3141 return 0 | |
| 3076 | 3142 |
| 3077 def CMDstatus(parser, args): | 3143 def CMDstatus(parser, args): |
| 3078 """Show status of changelists. | 3144 """Show status of changelists. |
| 3079 | 3145 |
| 3080 Colors are used to tell the state of the CL unless --fast is used: | 3146 Colors are used to tell the state of the CL unless --fast is used: |
| 3081 - Red not sent for review or broken | 3147 - Red not sent for review or broken |
| 3082 - Blue waiting for review | 3148 - Blue waiting for review |
| 3083 - Yellow waiting for you to reply to review | 3149 - Yellow waiting for you to reply to review |
| 3084 - Green LGTM'ed | 3150 - Green LGTM'ed |
| 3085 - Magenta in the commit queue | 3151 - Magenta in the commit queue |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4887 if __name__ == '__main__': | 4953 if __name__ == '__main__': |
| 4888 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4954 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 4889 # unit testing. | 4955 # unit testing. |
| 4890 fix_encoding.fix_encoding() | 4956 fix_encoding.fix_encoding() |
| 4891 setup_color.init() | 4957 setup_color.init() |
| 4892 try: | 4958 try: |
| 4893 sys.exit(main(sys.argv[1:])) | 4959 sys.exit(main(sys.argv[1:])) |
| 4894 except KeyboardInterrupt: | 4960 except KeyboardInterrupt: |
| 4895 sys.stderr.write('interrupted\n') | 4961 sys.stderr.write('interrupted\n') |
| 4896 sys.exit(1) | 4962 sys.exit(1) |
| OLD | NEW |