OLD | NEW |
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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 # the string and return code 0. So strip one character to force 'git | 484 # the string and return code 0. So strip one character to force 'git |
485 # rev-parse' to do a hash table look-up and returns 128 if the hash is not | 485 # rev-parse' to do a hash table look-up and returns 128 if the hash is not |
486 # present. | 486 # present. |
487 lookup_rev = rev | 487 lookup_rev = rev |
488 if re.match(r'^[0-9a-fA-F]{40}$', rev): | 488 if re.match(r'^[0-9a-fA-F]{40}$', rev): |
489 lookup_rev = rev[:-1] | 489 lookup_rev = rev[:-1] |
490 try: | 490 try: |
491 sha = GIT.Capture(['rev-parse', lookup_rev], cwd=cwd).lower() | 491 sha = GIT.Capture(['rev-parse', lookup_rev], cwd=cwd).lower() |
492 if lookup_rev != rev: | 492 if lookup_rev != rev: |
493 # Make sure we get the original 40 chars back. | 493 # Make sure we get the original 40 chars back. |
494 return rev.lower() == sha | 494 if rev.lower() != sha: |
| 495 return False |
495 if sha_only: | 496 if sha_only: |
496 return sha.startswith(rev.lower()) | 497 if not sha.startswith(rev.lower()): |
497 return True | 498 return False |
498 except subprocess2.CalledProcessError: | 499 except subprocess2.CalledProcessError: |
499 return False | 500 return False |
| 501 obj_type = GIT.Capture(['cat-file', '-t', rev], cwd=cwd).strip() |
| 502 return obj_type == 'commit' |
500 | 503 |
501 @classmethod | 504 @classmethod |
502 def AssertVersion(cls, min_version): | 505 def AssertVersion(cls, min_version): |
503 """Asserts git's version is at least min_version.""" | 506 """Asserts git's version is at least min_version.""" |
504 if cls.current_version is None: | 507 if cls.current_version is None: |
505 current_version = cls.Capture(['--version'], '.') | 508 current_version = cls.Capture(['--version'], '.') |
506 matched = re.search(r'version ([0-9\.]+)', current_version) | 509 matched = re.search(r'version ([0-9\.]+)', current_version) |
507 cls.current_version = matched.group(1) | 510 cls.current_version = matched.group(1) |
508 current_version_list = map(only_int, cls.current_version.split('.')) | 511 current_version_list = map(only_int, cls.current_version.split('.')) |
509 for min_ver in map(int, min_version.split('.')): | 512 for min_ver in map(int, min_version.split('.')): |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 # revert, like for properties. | 1140 # revert, like for properties. |
1138 if not os.path.isdir(cwd): | 1141 if not os.path.isdir(cwd): |
1139 # '.' was deleted. It's not worth continuing. | 1142 # '.' was deleted. It's not worth continuing. |
1140 return | 1143 return |
1141 try: | 1144 try: |
1142 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1145 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
1143 except subprocess2.CalledProcessError: | 1146 except subprocess2.CalledProcessError: |
1144 if not os.path.exists(file_path): | 1147 if not os.path.exists(file_path): |
1145 continue | 1148 continue |
1146 raise | 1149 raise |
OLD | NEW |