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

Side by Side Diff: git_cl.py

Issue 2267833002: More debug. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@hahaha
Patch Set: More debug. Created 4 years, 4 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 __future__ import print_function 10 from __future__ import print_function
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 def GetNoGitPagerEnv(): 91 def GetNoGitPagerEnv():
92 env = os.environ.copy() 92 env = os.environ.copy()
93 # 'cat' is a magical git string that disables pagers on all platforms. 93 # 'cat' is a magical git string that disables pagers on all platforms.
94 env['GIT_PAGER'] = 'cat' 94 env['GIT_PAGER'] = 'cat'
95 return env 95 return env
96 96
97 97
98 def RunCommand(args, error_ok=False, error_message=None, shell=False, **kwargs): 98 def RunCommand(args, error_ok=False, error_message=None, shell=False, **kwargs):
99 try: 99 try:
100 return subprocess2.check_output(args, shell=shell, **kwargs) 100 out = subprocess2.check_output(args, shell=shell, **kwargs)
101 logging.debug('output of %s is\n%s\n', args,
102 '\n'.join(' ' + l for l in out.splitlines()))
103 return out
101 except subprocess2.CalledProcessError as e: 104 except subprocess2.CalledProcessError as e:
102 logging.debug('Failed running %s', args) 105 logging.debug('Failed running %s', args)
106 logging.debug('output of %s is\n%s\n', args,
107 '\n'.join(' ' + l for l in e.stdout.splitlines()) if e.stdout else '')
103 if not error_ok: 108 if not error_ok:
104 DieWithError( 109 DieWithError(
105 'Command "%s" failed.\n%s' % ( 110 'Command "%s" failed.\n%s' % (
106 ' '.join(args), error_message or e.stdout or '')) 111 ' '.join(args), error_message or e.stdout or ''))
107 return e.stdout 112 return e.stdout
108 113
109 114
110 def RunGit(args, **kwargs): 115 def RunGit(args, **kwargs):
111 """Returns stdout.""" 116 """Returns stdout."""
112 return RunCommand(['git'] + args, **kwargs) 117 return RunCommand(['git'] + args, **kwargs)
113 118
114 119
115 def RunGitWithCode(args, suppress_stderr=False): 120 def RunGitWithCode(args, suppress_stderr=False):
116 """Returns return code and stdout.""" 121 """Returns return code and stdout."""
117 if suppress_stderr: 122 if suppress_stderr:
118 stderr = subprocess2.VOID 123 stderr = subprocess2.VOID
119 else: 124 else:
120 stderr = sys.stderr 125 stderr = sys.stderr
121 try: 126 try:
122 (out, _), code = subprocess2.communicate(['git'] + args, 127 (out, _), code = subprocess2.communicate(['git'] + args,
123 env=GetNoGitPagerEnv(), 128 env=GetNoGitPagerEnv(),
124 stdout=subprocess2.PIPE, 129 stdout=subprocess2.PIPE,
125 stderr=stderr) 130 stderr=stderr)
131 logging.debug('output of %s is\n%s\n', args,
132 '\n'.join(' ' + l for l in out.splitlines()))
126 return code, out 133 return code, out
127 except subprocess2.CalledProcessError as e: 134 except subprocess2.CalledProcessError as e:
128 logging.debug('Failed running %s', args) 135 logging.debug('Failed running %s', args)
136 logging.debug('output of %s is\n%s\n', args,
137 '\n'.join(' ' + l for l in e.stdout.splitlines()) if e.stdout else '')
129 return e.returncode, e.stdout 138 return e.returncode, e.stdout
130 139
131 140
132 def RunGitSilent(args): 141 def RunGitSilent(args):
133 """Returns stdout, suppresses stderr and ignores the return code.""" 142 """Returns stdout, suppresses stderr and ignores the return code."""
134 return RunGitWithCode(args, suppress_stderr=True)[1] 143 return RunGitWithCode(args, suppress_stderr=True)[1]
135 144
136 145
137 def IsGitVersionAtLeast(min_version): 146 def IsGitVersionAtLeast(min_version):
138 prefix = 'git version ' 147 prefix = 'git version '
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 upload_args.extend(['--base_url', remote_url]) 2026 upload_args.extend(['--base_url', remote_url])
2018 remote, remote_branch = self.GetRemoteBranch() 2027 remote, remote_branch = self.GetRemoteBranch()
2019 target_ref = GetTargetRef(remote, remote_branch, options.target_branch, 2028 target_ref = GetTargetRef(remote, remote_branch, options.target_branch,
2020 settings.GetPendingRefPrefix()) 2029 settings.GetPendingRefPrefix())
2021 if target_ref: 2030 if target_ref:
2022 upload_args.extend(['--target_ref', target_ref]) 2031 upload_args.extend(['--target_ref', target_ref])
2023 2032
2024 # Look for dependent patchsets. See crbug.com/480453 for more details. 2033 # Look for dependent patchsets. See crbug.com/480453 for more details.
2025 remote, upstream_branch = self.FetchUpstreamTuple(self.GetBranch()) 2034 remote, upstream_branch = self.FetchUpstreamTuple(self.GetBranch())
2026 upstream_branch = ShortBranchName(upstream_branch) 2035 upstream_branch = ShortBranchName(upstream_branch)
2036 logging.debug('remote: %s, upstream: %s', remote, upstream_branch)
2027 if remote is '.': 2037 if remote is '.':
2028 # A local branch is being tracked. 2038 # A local branch is being tracked.
2029 local_branch = upstream_branch 2039 local_branch = upstream_branch
2030 if settings.GetIsSkipDependencyUpload(local_branch): 2040 if settings.GetIsSkipDependencyUpload(local_branch):
2031 print() 2041 print()
2032 print('Skipping dependency patchset upload because git config ' 2042 print('Skipping dependency patchset upload because git config '
2033 'branch.%s.skip-deps-uploads is set to True.' % local_branch) 2043 'branch.%s.skip-deps-uploads is set to True.' % local_branch)
2034 print() 2044 print()
2035 else: 2045 else:
2036 auth_config = auth.extract_auth_config_from_options(options) 2046 auth_config = auth.extract_auth_config_from_options(options)
2037 branch_cl = Changelist(branchref='refs/heads/'+local_branch, 2047 branch_cl = Changelist(branchref='refs/heads/'+local_branch,
2038 auth_config=auth_config) 2048 auth_config=auth_config)
2049 logging.debug('upstream cl: Gerrit=%s', branch_cl.IsGerrit())
2039 branch_cl_issue_url = branch_cl.GetIssueURL() 2050 branch_cl_issue_url = branch_cl.GetIssueURL()
2040 branch_cl_issue = branch_cl.GetIssue() 2051 branch_cl_issue = branch_cl.GetIssue()
2041 branch_cl_patchset = branch_cl.GetPatchset() 2052 branch_cl_patchset = branch_cl.GetPatchset()
2053 logging.debug('upstream cl: url %s issue %s pachset %s',
2054 branch_cl_issue_url, branch_cl_issue , branch_cl_patchset)
2055
2042 if branch_cl_issue_url and branch_cl_issue and branch_cl_patchset: 2056 if branch_cl_issue_url and branch_cl_issue and branch_cl_patchset:
2043 upload_args.extend( 2057 upload_args.extend(
2044 ['--depends_on_patchset', '%s:%s' % ( 2058 ['--depends_on_patchset', '%s:%s' % (
2045 branch_cl_issue, branch_cl_patchset)]) 2059 branch_cl_issue, branch_cl_patchset)])
2046 print( 2060 print(
2047 '\n' 2061 '\n'
2048 'The current branch (%s) is tracking a local branch (%s) with ' 2062 'The current branch (%s) is tracking a local branch (%s) with '
2049 'an associated CL.\n' 2063 'an associated CL.\n'
2050 'Adding %s/#ps%s as a dependency patchset.\n' 2064 'Adding %s/#ps%s as a dependency patchset.\n'
2051 '\n' % (self.GetBranch(), local_branch, branch_cl_issue_url, 2065 '\n' % (self.GetBranch(), local_branch, branch_cl_issue_url,
(...skipping 3150 matching lines...) Expand 10 before | Expand all | Expand 10 after
5202 if __name__ == '__main__': 5216 if __name__ == '__main__':
5203 # These affect sys.stdout so do it outside of main() to simplify mocks in 5217 # These affect sys.stdout so do it outside of main() to simplify mocks in
5204 # unit testing. 5218 # unit testing.
5205 fix_encoding.fix_encoding() 5219 fix_encoding.fix_encoding()
5206 setup_color.init() 5220 setup_color.init()
5207 try: 5221 try:
5208 sys.exit(main(sys.argv[1:])) 5222 sys.exit(main(sys.argv[1:]))
5209 except KeyboardInterrupt: 5223 except KeyboardInterrupt:
5210 sys.stderr.write('interrupted\n') 5224 sys.stderr.write('interrupted\n')
5211 sys.exit(1) 5225 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