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 2973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2984 # Silence upload.py otherwise it becomes unwieldly. | 2984 # Silence upload.py otherwise it becomes unwieldly. |
2985 upload.verbosity = 0 | 2985 upload.verbosity = 0 |
2986 | 2986 |
2987 if fine_grained: | 2987 if fine_grained: |
2988 # Process one branch synchronously to work through authentication, then | 2988 # Process one branch synchronously to work through authentication, then |
2989 # spawn processes to process all the other branches in parallel. | 2989 # spawn processes to process all the other branches in parallel. |
2990 if changes: | 2990 if changes: |
2991 fetch = lambda cl: (cl, cl.GetStatus()) | 2991 fetch = lambda cl: (cl, cl.GetStatus()) |
2992 yield fetch(changes[0]) | 2992 yield fetch(changes[0]) |
2993 | 2993 |
| 2994 if not changes: |
| 2995 # Exit early if there was only one branch to fetch. |
| 2996 return |
| 2997 |
2994 changes_to_fetch = changes[1:] | 2998 changes_to_fetch = changes[1:] |
2995 pool = ThreadPool( | 2999 pool = ThreadPool( |
2996 min(max_processes, len(changes_to_fetch)) | 3000 min(max_processes, len(changes_to_fetch)) |
2997 if max_processes is not None | 3001 if max_processes is not None |
2998 else len(changes_to_fetch)) | 3002 else len(changes_to_fetch)) |
2999 | 3003 |
3000 fetched_cls = set() | 3004 fetched_cls = set() |
3001 it = pool.imap_unordered(fetch, changes_to_fetch).__iter__() | 3005 it = pool.imap_unordered(fetch, changes_to_fetch).__iter__() |
3002 while True: | 3006 while True: |
3003 try: | 3007 try: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 print | 3115 print |
3112 print 'Upload complete for dependent branches!' | 3116 print 'Upload complete for dependent branches!' |
3113 for dependent_branch in dependents: | 3117 for dependent_branch in dependents: |
3114 upload_status = 'failed' if failures.get(dependent_branch) else 'succeeded' | 3118 upload_status = 'failed' if failures.get(dependent_branch) else 'succeeded' |
3115 print ' %s : %s' % (dependent_branch, upload_status) | 3119 print ' %s : %s' % (dependent_branch, upload_status) |
3116 print | 3120 print |
3117 | 3121 |
3118 return 0 | 3122 return 0 |
3119 | 3123 |
3120 | 3124 |
| 3125 def CMDarchive(parser, args): |
| 3126 """Archives and deletes branches associated with closed changelists.""" |
| 3127 parser.add_option( |
| 3128 '-j', '--maxjobs', action='store', type=int, |
| 3129 help='The maximum number of jobs to use when retrieving review status') |
| 3130 parser.add_option( |
| 3131 '-f', '--force', action='store_true', |
| 3132 help='Bypasses the confirmation prompt.') |
| 3133 |
| 3134 auth.add_auth_options(parser) |
| 3135 options, args = parser.parse_args(args) |
| 3136 if args: |
| 3137 parser.error('Unsupported args: %s' % ' '.join(args)) |
| 3138 auth_config = auth.extract_auth_config_from_options(options) |
| 3139 |
| 3140 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) |
| 3141 if not branches: |
| 3142 return 0 |
| 3143 |
| 3144 print 'Finding all branches associated with closed issues...' |
| 3145 changes = [Changelist(branchref=b, auth_config=auth_config) |
| 3146 for b in branches.splitlines()] |
| 3147 alignment = max(5, max(len(c.GetBranch()) for c in changes)) |
| 3148 statuses = get_cl_statuses(changes, |
| 3149 fine_grained=True, |
| 3150 max_processes=options.maxjobs) |
| 3151 proposal = [(cl.GetBranch(), |
| 3152 'git-cl-archived-%s-%s' % (cl.GetIssue(), cl.GetBranch())) |
| 3153 for cl, status in statuses |
| 3154 if status == 'closed'] |
| 3155 proposal.sort() |
| 3156 |
| 3157 if not proposal: |
| 3158 print 'No branches with closed codereview issues found.' |
| 3159 return 0 |
| 3160 |
| 3161 current_branch = GetCurrentBranch() |
| 3162 |
| 3163 print '\nBranches with closed issues that will be archived:\n' |
| 3164 print '%*s | %s' % (alignment, 'Branch name', 'Archival tag name') |
| 3165 for next_item in proposal: |
| 3166 print '%*s %s' % (alignment, next_item[0], next_item[1]) |
| 3167 |
| 3168 if any(branch == current_branch for branch, _ in proposal): |
| 3169 print('You are currently on a branch \'%s\' which is associated with a ' |
| 3170 'closed codereview issue, so archive cannot proceed. Please ' |
| 3171 'checkout another branch and run this command again.' % |
| 3172 current_branch) |
| 3173 return 1 |
| 3174 |
| 3175 if not options.force: |
| 3176 if ask_for_data('\nProceed with deletion (Y/N)? ').lower() != 'y': |
| 3177 print 'Aborted.' |
| 3178 return 1 |
| 3179 |
| 3180 for branch, tagname in proposal: |
| 3181 RunGit(['tag', tagname, branch]) |
| 3182 RunGit(['branch', '-D', branch]) |
| 3183 print '\nJob\'s done!' |
| 3184 |
| 3185 return 0 |
| 3186 |
| 3187 |
3121 def CMDstatus(parser, args): | 3188 def CMDstatus(parser, args): |
3122 """Show status of changelists. | 3189 """Show status of changelists. |
3123 | 3190 |
3124 Colors are used to tell the state of the CL unless --fast is used: | 3191 Colors are used to tell the state of the CL unless --fast is used: |
3125 - Red not sent for review or broken | 3192 - Red not sent for review or broken |
3126 - Blue waiting for review | 3193 - Blue waiting for review |
3127 - Yellow waiting for you to reply to review | 3194 - Yellow waiting for you to reply to review |
3128 - Green LGTM'ed | 3195 - Green LGTM'ed |
3129 - Magenta in the commit queue | 3196 - Magenta in the commit queue |
3130 - Cyan was committed, branch can be deleted | 3197 - Cyan was committed, branch can be deleted |
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4932 if __name__ == '__main__': | 4999 if __name__ == '__main__': |
4933 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5000 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4934 # unit testing. | 5001 # unit testing. |
4935 fix_encoding.fix_encoding() | 5002 fix_encoding.fix_encoding() |
4936 setup_color.init() | 5003 setup_color.init() |
4937 try: | 5004 try: |
4938 sys.exit(main(sys.argv[1:])) | 5005 sys.exit(main(sys.argv[1:])) |
4939 except KeyboardInterrupt: | 5006 except KeyboardInterrupt: |
4940 sys.stderr.write('interrupted\n') | 5007 sys.stderr.write('interrupted\n') |
4941 sys.exit(1) | 5008 sys.exit(1) |
OLD | NEW |