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

Side by Side Diff: git_cl.py

Issue 1893563002: Use CLs more consistently instead of branch names (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: address tandrii's comments Created 4 years, 8 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 | no next file » | 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
11 from multiprocessing.pool import ThreadPool 11 from multiprocessing.pool import ThreadPool
12 import base64 12 import base64
13 import collections 13 import collections
14 import glob 14 import glob
15 import httplib 15 import httplib
16 import json 16 import json
17 import logging 17 import logging
18 import optparse 18 import optparse
19 import os 19 import os
20 import Queue
21 import re 20 import re
22 import stat 21 import stat
23 import sys 22 import sys
24 import tempfile
25 import textwrap 23 import textwrap
26 import time 24 import time
27 import traceback 25 import traceback
28 import urllib 26 import urllib
29 import urllib2 27 import urllib2
30 import urlparse 28 import urlparse
31 import uuid 29 import uuid
32 import webbrowser 30 import webbrowser
33 import zlib 31 import zlib
34 32
(...skipping 2857 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 return { 2890 return {
2893 'unsent': Fore.RED, 2891 'unsent': Fore.RED,
2894 'waiting': Fore.BLUE, 2892 'waiting': Fore.BLUE,
2895 'reply': Fore.YELLOW, 2893 'reply': Fore.YELLOW,
2896 'lgtm': Fore.GREEN, 2894 'lgtm': Fore.GREEN,
2897 'commit': Fore.MAGENTA, 2895 'commit': Fore.MAGENTA,
2898 'closed': Fore.CYAN, 2896 'closed': Fore.CYAN,
2899 'error': Fore.WHITE, 2897 'error': Fore.WHITE,
2900 }.get(status, Fore.WHITE) 2898 }.get(status, Fore.WHITE)
2901 2899
2902 def fetch_cl_status(branch, auth_config=None):
2903 """Fetches information for an issue and returns (branch, issue, status)."""
2904 cl = Changelist(branchref=branch, auth_config=auth_config)
2905 url = cl.GetIssueURL()
2906 status = cl.GetStatus()
2907
2908 if url and (not status or status == 'error'):
2909 # The issue probably doesn't exist anymore.
2910 url += ' (broken)'
2911
2912 return (branch, url, status)
2913
2914 def get_cl_statuses( 2900 def get_cl_statuses(
2915 branches, fine_grained, max_processes=None, auth_config=None): 2901 changes, fine_grained, max_processes=None, auth_config=None):
tandrii(chromium) 2016/04/24 18:33:12 remove unused auth_config kwarg.
Clemens Hammacher 2016/04/25 08:19:59 done.
2916 """Returns a blocking iterable of (branch, issue, color) for given branches. 2902 """Returns a blocking iterable of (branch, issue, color) for given branches.
2917 2903
2918 If fine_grained is true, this will fetch CL statuses from the server. 2904 If fine_grained is true, this will fetch CL statuses from the server.
2919 Otherwise, simply indicate if there's a matching url for the given branches. 2905 Otherwise, simply indicate if there's a matching url for the given branches.
2920 2906
2921 If max_processes is specified, it is used as the maximum number of processes 2907 If max_processes is specified, it is used as the maximum number of processes
2922 to spawn to fetch CL status from the server. Otherwise 1 process per branch is 2908 to spawn to fetch CL status from the server. Otherwise 1 process per branch is
2923 spawned. 2909 spawned.
2924 """ 2910 """
2925 # Silence upload.py otherwise it becomes unwieldly. 2911 # Silence upload.py otherwise it becomes unwieldly.
2926 upload.verbosity = 0 2912 upload.verbosity = 0
2927 2913
2928 if fine_grained: 2914 if fine_grained:
2929 # Process one branch synchronously to work through authentication, then 2915 # Process one branch synchronously to work through authentication, then
2930 # spawn processes to process all the other branches in parallel. 2916 # spawn processes to process all the other branches in parallel.
2931 if branches: 2917 if changes:
2932 fetch = lambda branch: fetch_cl_status(branch, auth_config=auth_config) 2918 fetch = lambda cl: (cl, cl.GetStatus())
2933 yield fetch(branches[0]) 2919 yield fetch(changes[0])
2934 2920
2935 branches_to_fetch = branches[1:] 2921 changes_to_fetch = changes[1:]
2936 pool = ThreadPool( 2922 pool = ThreadPool(
2937 min(max_processes, len(branches_to_fetch)) 2923 min(max_processes, len(changes_to_fetch))
2938 if max_processes is not None 2924 if max_processes is not None
2939 else len(branches_to_fetch)) 2925 else len(changes_to_fetch))
2940 for x in pool.imap_unordered(fetch, branches_to_fetch): 2926 for x in pool.imap_unordered(fetch, changes_to_fetch):
2941 yield x 2927 yield x
2942 else: 2928 else:
2943 # Do not use GetApprovingReviewers(), since it requires an HTTP request. 2929 # Do not use GetApprovingReviewers(), since it requires an HTTP request.
2944 for b in branches: 2930 for cl in changes:
2945 cl = Changelist(branchref=b, auth_config=auth_config) 2931 yield (cl, 'waiting' if cl.GetIssueURL() else 'error')
2946 url = cl.GetIssueURL()
2947 yield (b, url, 'waiting' if url else 'error')
2948 2932
2949 2933
2950 def upload_branch_deps(cl, args): 2934 def upload_branch_deps(cl, args):
2951 """Uploads CLs of local branches that are dependents of the current branch. 2935 """Uploads CLs of local branches that are dependents of the current branch.
2952 2936
2953 If the local branch dependency tree looks like: 2937 If the local branch dependency tree looks like:
2954 test1 -> test2.1 -> test3.1 2938 test1 -> test2.1 -> test3.1
2955 -> test3.2 2939 -> test3.2
2956 -> test2.2 -> test3.3 2940 -> test2.2 -> test3.3
2957 2941
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3090 url = cl.GetIssueURL() 3074 url = cl.GetIssueURL()
3091 if url: 3075 if url:
3092 print url 3076 print url
3093 return 0 3077 return 0
3094 3078
3095 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) 3079 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads'])
3096 if not branches: 3080 if not branches:
3097 print('No local branch found.') 3081 print('No local branch found.')
3098 return 0 3082 return 0
3099 3083
3100 changes = ( 3084 changes = [
3101 Changelist(branchref=b, auth_config=auth_config) 3085 Changelist(branchref=b, auth_config=auth_config)
3102 for b in branches.splitlines()) 3086 for b in branches.splitlines()]
3103 # TODO(tandrii): refactor to use CLs list instead of branches list.
3104 branches = [c.GetBranch() for c in changes]
3105 alignment = max(5, max(len(b) for b in branches))
3106 print 'Branches associated with reviews:' 3087 print 'Branches associated with reviews:'
3107 output = get_cl_statuses(branches, 3088 output = get_cl_statuses(changes,
3108 fine_grained=not options.fast, 3089 fine_grained=not options.fast,
3109 max_processes=options.maxjobs, 3090 max_processes=options.maxjobs,
3110 auth_config=auth_config) 3091 auth_config=auth_config)
tandrii(chromium) 2016/04/24 18:33:12 (cont) and this kwarg is not needed.
Clemens Hammacher 2016/04/25 08:19:59 done.
3111 3092
3112 branch_statuses = {} 3093 branch_statuses = {}
3113 alignment = max(5, max(len(ShortBranchName(b)) for b in branches)) 3094 alignment = max(5, max(len(ShortBranchName(c.GetBranch())) for c in changes))
3114 for branch in sorted(branches): 3095 for cl in sorted(changes, key=lambda c: c.GetBranch()):
3096 branch = cl.GetBranch()
3115 while branch not in branch_statuses: 3097 while branch not in branch_statuses:
3116 b, i, status = output.next() 3098 c, status = output.next()
3117 branch_statuses[b] = (i, status) 3099 branch_statuses[c.GetBranch()] = status
3118 issue_url, status = branch_statuses.pop(branch) 3100 status = branch_statuses.pop(branch)
3101 url = cl.GetIssueURL()
3102 if url and (not status or status == 'error'):
3103 # The issue probably doesn't exist anymore.
3104 url += ' (broken)'
3105
3119 color = color_for_status(status) 3106 color = color_for_status(status)
3120 reset = Fore.RESET 3107 reset = Fore.RESET
3121 if not setup_color.IS_TTY: 3108 if not setup_color.IS_TTY:
3122 color = '' 3109 color = ''
3123 reset = '' 3110 reset = ''
3124 status_str = '(%s)' % status if status else '' 3111 status_str = '(%s)' % status if status else ''
3125 print ' %*s : %s%s %s%s' % ( 3112 print ' %*s : %s%s %s%s' % (
3126 alignment, ShortBranchName(branch), color, issue_url, status_str, 3113 alignment, ShortBranchName(branch), color, url,
3127 reset) 3114 status_str, reset)
3128 3115
3129 cl = Changelist(auth_config=auth_config) 3116 cl = Changelist(auth_config=auth_config)
3130 print 3117 print
3131 print 'Current branch:', 3118 print 'Current branch:',
3132 print cl.GetBranch() 3119 print cl.GetBranch()
3133 if not cl.GetIssue(): 3120 if not cl.GetIssue():
3134 print 'No issue assigned.' 3121 print 'No issue assigned.'
3135 return 0 3122 return 0
3136 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) 3123 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL())
3137 if not options.fast: 3124 if not options.fast:
(...skipping 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after
4828 if __name__ == '__main__': 4815 if __name__ == '__main__':
4829 # These affect sys.stdout so do it outside of main() to simplify mocks in 4816 # These affect sys.stdout so do it outside of main() to simplify mocks in
4830 # unit testing. 4817 # unit testing.
4831 fix_encoding.fix_encoding() 4818 fix_encoding.fix_encoding()
4832 setup_color.init() 4819 setup_color.init()
4833 try: 4820 try:
4834 sys.exit(main(sys.argv[1:])) 4821 sys.exit(main(sys.argv[1:]))
4835 except KeyboardInterrupt: 4822 except KeyboardInterrupt:
4836 sys.stderr.write('interrupted\n') 4823 sys.stderr.write('interrupted\n')
4837 sys.exit(1) 4824 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698