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

Side by Side Diff: scm.py

Issue 18292005: Fix bug with parsing capitalized git shas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« 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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """SCM-specific utility classes.""" 5 """SCM-specific utility classes."""
6 6
7 import cStringIO 7 import cStringIO
8 import glob 8 import glob
9 import logging 9 import logging
10 import os 10 import os
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 sha_only: Fail unless rev is a sha hash. 447 sha_only: Fail unless rev is a sha hash.
448 """ 448 """
449 # 'git rev-parse foo' where foo is *any* 40 character hex string will return 449 # 'git rev-parse foo' where foo is *any* 40 character hex string will return
450 # the string and return code 0. So strip one character to force 'git 450 # the string and return code 0. So strip one character to force 'git
451 # rev-parse' to do a hash table look-up and returns 128 if the hash is not 451 # rev-parse' to do a hash table look-up and returns 128 if the hash is not
452 # present. 452 # present.
453 lookup_rev = rev 453 lookup_rev = rev
454 if re.match(r'^[0-9a-fA-F]{40}$', rev): 454 if re.match(r'^[0-9a-fA-F]{40}$', rev):
455 lookup_rev = rev[:-1] 455 lookup_rev = rev[:-1]
456 try: 456 try:
457 sha = GIT.Capture(['rev-parse', lookup_rev], cwd=cwd) 457 sha = GIT.Capture(['rev-parse', lookup_rev], cwd=cwd).lower()
458 if lookup_rev != rev: 458 if lookup_rev != rev:
459 # Make sure we get the original 40 chars back. 459 # Make sure we get the original 40 chars back.
460 return rev == sha 460 return rev.lower() == sha
461 if sha_only: 461 if sha_only:
462 return sha.startswith(rev) 462 return sha.startswith(rev.lower())
463 return True 463 return True
464 except subprocess2.CalledProcessError: 464 except subprocess2.CalledProcessError:
465 return False 465 return False
466 466
467 @classmethod 467 @classmethod
468 def AssertVersion(cls, min_version): 468 def AssertVersion(cls, min_version):
469 """Asserts git's version is at least min_version.""" 469 """Asserts git's version is at least min_version."""
470 if cls.current_version is None: 470 if cls.current_version is None:
471 current_version = cls.Capture(['--version'], '.') 471 current_version = cls.Capture(['--version'], '.')
472 matched = re.search(r'version ([0-9\.]+)', current_version) 472 matched = re.search(r'version ([0-9\.]+)', current_version)
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 # revert, like for properties. 1103 # revert, like for properties.
1104 if not os.path.isdir(cwd): 1104 if not os.path.isdir(cwd):
1105 # '.' was deleted. It's not worth continuing. 1105 # '.' was deleted. It's not worth continuing.
1106 return 1106 return
1107 try: 1107 try:
1108 SVN.Capture(['revert', file_status[1]], cwd=cwd) 1108 SVN.Capture(['revert', file_status[1]], cwd=cwd)
1109 except subprocess2.CalledProcessError: 1109 except subprocess2.CalledProcessError:
1110 if not os.path.exists(file_path): 1110 if not os.path.exists(file_path):
1111 continue 1111 continue
1112 raise 1112 raise
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