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

Side by Side Diff: git_cl.py

Issue 2272613002: git cl: workaround against integer overflows of git config. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 3 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 | tests/git_cl_test.py » ('j') | 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 Returns default in all other cases. 169 Returns default in all other cases.
170 """ 170 """
171 assert value_type in (int, str, bool) 171 assert value_type in (int, str, bool)
172 if branch is False: # Distinguishing default arg value from None. 172 if branch is False: # Distinguishing default arg value from None.
173 branch = GetCurrentBranch() 173 branch = GetCurrentBranch()
174 174
175 if not branch: 175 if not branch:
176 return default 176 return default
177 177
178 args = ['config'] 178 args = ['config']
179 if value_type == int: 179 if value_type == bool:
180 args.append('--int')
181 elif value_type == bool:
182 args.append('--bool') 180 args.append('--bool')
181 # git config also has --int, but apparently git config suffers from integer
182 # overflows (http://crbug.com/640115), so don't use it.
183 args.append(_git_branch_config_key(branch, key)) 183 args.append(_git_branch_config_key(branch, key))
184 code, out = RunGitWithCode(args) 184 code, out = RunGitWithCode(args)
185 if code == 0: 185 if code == 0:
186 value = out.strip() 186 value = out.strip()
187 if value_type == int: 187 if value_type == int:
188 return int(value) 188 return int(value)
189 if value_type == bool: 189 if value_type == bool:
190 return bool(value.lower() == 'true') 190 return bool(value.lower() == 'true')
191 return value 191 return value
192 return default 192 return default
193 193
194 194
195 def _git_set_branch_config_value(key, value, branch=None, **kwargs): 195 def _git_set_branch_config_value(key, value, branch=None, **kwargs):
196 """Sets the value or unsets if it's None of a git branch config. 196 """Sets the value or unsets if it's None of a git branch config.
197 197
198 Valid, though not necessarily existing, branch must be provided, 198 Valid, though not necessarily existing, branch must be provided,
199 otherwise currently checked out branch is used. 199 otherwise currently checked out branch is used.
200 """ 200 """
201 if not branch: 201 if not branch:
202 branch = GetCurrentBranch() 202 branch = GetCurrentBranch()
203 assert branch, 'a branch name OR currently checked out branch is required' 203 assert branch, 'a branch name OR currently checked out branch is required'
204 args = ['config'] 204 args = ['config']
205 # Check for boolean first, becuase bool is int, but int is not bool. 205 # Check for boolean first, becuase bool is int, but int is not bool.
206 if value is None: 206 if value is None:
207 args.append('--unset') 207 args.append('--unset')
208 elif isinstance(value, bool): 208 elif isinstance(value, bool):
209 args.append('--bool') 209 args.append('--bool')
210 value = str(value).lower() 210 value = str(value).lower()
211 elif isinstance(value, int):
212 args.append('--int')
213 value = str(value)
214 else: 211 else:
212 # git config also has --int, but apparently git config suffers from integer
213 # overflows (http://crbug.com/640115), so don't use it.
215 value = str(value) 214 value = str(value)
216 args.append(_git_branch_config_key(branch, key)) 215 args.append(_git_branch_config_key(branch, key))
217 if value is not None: 216 if value is not None:
218 args.append(value) 217 args.append(value)
219 RunGit(args, **kwargs) 218 RunGit(args, **kwargs)
220 219
221 220
222 def add_git_similarity(parser): 221 def add_git_similarity(parser):
223 parser.add_option( 222 parser.add_option(
224 '--similarity', metavar='SIM', type=int, action='store', 223 '--similarity', metavar='SIM', type=int, action='store',
(...skipping 4977 matching lines...) Expand 10 before | Expand all | Expand 10 after
5202 if __name__ == '__main__': 5201 if __name__ == '__main__':
5203 # These affect sys.stdout so do it outside of main() to simplify mocks in 5202 # These affect sys.stdout so do it outside of main() to simplify mocks in
5204 # unit testing. 5203 # unit testing.
5205 fix_encoding.fix_encoding() 5204 fix_encoding.fix_encoding()
5206 setup_color.init() 5205 setup_color.init()
5207 try: 5206 try:
5208 sys.exit(main(sys.argv[1:])) 5207 sys.exit(main(sys.argv[1:]))
5209 except KeyboardInterrupt: 5208 except KeyboardInterrupt:
5210 sys.stderr.write('interrupted\n') 5209 sys.stderr.write('interrupted\n')
5211 sys.exit(1) 5210 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698