Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd=cwd).strip() | 372 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd=cwd).strip() |
| 373 return "%s#%s" % (GIT.GetBranch(cwd), short_sha) | 373 return "%s#%s" % (GIT.GetBranch(cwd), short_sha) |
| 374 | 374 |
| 375 @staticmethod | 375 @staticmethod |
| 376 def GetCheckoutRoot(cwd): | 376 def GetCheckoutRoot(cwd): |
| 377 """Returns the top level directory of a git checkout as an absolute path. | 377 """Returns the top level directory of a git checkout as an absolute path. |
| 378 """ | 378 """ |
| 379 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip() | 379 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip() |
| 380 return os.path.abspath(os.path.join(cwd, root)) | 380 return os.path.abspath(os.path.join(cwd, root)) |
| 381 | 381 |
| 382 @staticmethod | |
| 383 def GetGitSvnHeadRev(cwd): | |
| 384 """Gets the most recently pulled git-svn revision.""" | |
| 385 try: | |
| 386 output = GIT.Capture(['svn', 'info'], cwd=cwd) | |
| 387 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE) | |
| 388 if match: | |
| 389 print('Match found! ' + match.group(1)) | |
|
M-A Ruel
2011/11/09 14:16:08
That was for debugging?
Dan Beam
2011/11/09 19:21:59
Ah, yeah, sorry. Will remove.
Dan Beam
2011/11/10 10:29:15
Done.
| |
| 390 else: | |
| 391 print('Match not found, :(') | |
| 392 return int(match.group(1)) if match else None | |
| 393 except (subprocess2.CalledProcessError, ValueError): | |
| 394 return None | |
| 395 | |
| 396 @staticmethod | |
| 397 def GetSha1ForSvnRev(cwd, rev): | |
| 398 """Returns a corresponding git sha1 for a SVN revision.""" | |
| 399 if not GIT.IsGitSvn(cwd=cwd): | |
| 400 return None | |
| 401 try: | |
| 402 lines = GIT.Capture( | |
| 403 ['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).splitlines() | |
| 404 return lines[-1].strip() if len(lines) else None | |
|
M-A Ruel
2011/11/09 14:16:08
if lines
len() is unnecessary here.
Dan Beam
2011/11/10 10:29:15
Done.
| |
| 405 except subprocess2.CalledProcessError: | |
| 406 return None | |
| 407 | |
| 408 @staticmethod | |
| 409 def IsValidRevision(cwd, url, rev): | |
|
M-A Ruel
2011/11/09 14:16:08
Why url here?
Dan Beam
2011/11/09 19:21:59
To let scm.{GIT,SVN}.IsValidRevision() take the sa
M-A Ruel
2011/11/09 19:25:51
I prefer not. It's fine to have different interfac
Dan Beam
2011/11/09 19:37:22
OK, great, will change!
Dan Beam
2011/11/10 10:29:15
Done.
| |
| 410 """Verifies the revision is a proper git revision.""" | |
| 411 try: | |
| 412 GIT.Capture(['rev-parse', rev], cwd=cwd) | |
| 413 return True | |
| 414 except subprocess2.CalledProcessError: | |
| 415 return False | |
| 416 | |
| 382 @classmethod | 417 @classmethod |
| 383 def AssertVersion(cls, min_version): | 418 def AssertVersion(cls, min_version): |
| 384 """Asserts git's version is at least min_version.""" | 419 """Asserts git's version is at least min_version.""" |
| 385 if cls.current_version is None: | 420 if cls.current_version is None: |
| 386 cls.current_version = cls.Capture(['--version']).split()[-1] | 421 cls.current_version = cls.Capture(['--version']).split()[-1] |
| 387 current_version_list = map(only_int, cls.current_version.split('.')) | 422 current_version_list = map(only_int, cls.current_version.split('.')) |
| 388 for min_ver in map(int, min_version.split('.')): | 423 for min_ver in map(int, min_version.split('.')): |
| 389 ver = current_version_list.pop(0) | 424 ver = current_version_list.pop(0) |
| 390 if ver < min_ver: | 425 if ver < min_ver: |
| 391 return (False, cls.current_version) | 426 return (False, cls.current_version) |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 info = SVN.CaptureInfo(parent) | 957 info = SVN.CaptureInfo(parent) |
| 923 if (info['Repository Root'] != cur_dir_repo_root or | 958 if (info['Repository Root'] != cur_dir_repo_root or |
| 924 info['URL'] != os.path.dirname(url)): | 959 info['URL'] != os.path.dirname(url)): |
| 925 break | 960 break |
| 926 url = info['URL'] | 961 url = info['URL'] |
| 927 except subprocess2.CalledProcessError: | 962 except subprocess2.CalledProcessError: |
| 928 break | 963 break |
| 929 directory = parent | 964 directory = parent |
| 930 return GetCasedPath(directory) | 965 return GetCasedPath(directory) |
| 931 | 966 |
| 967 @staticmethod | |
| 968 def IsValidRevision(cwd, url, rev): | |
|
M-A Ruel
2011/11/09 14:16:08
Remove url from here, have the caller reformat wha
Dan Beam
2011/11/09 19:21:59
Same reason as above, make both methods take same
Dan Beam
2011/11/10 10:29:15
Done.
| |
| 969 """Verifies the revision looks like an SVN revision.""" | |
| 970 try: | |
| 971 SVN.Capture(['info', '%s@%s' % (url, rev)]) | |
| 972 return True | |
| 973 except subprocess2.CalledProcessError: | |
| 974 return False | |
| 975 | |
| 932 @classmethod | 976 @classmethod |
| 933 def AssertVersion(cls, min_version): | 977 def AssertVersion(cls, min_version): |
| 934 """Asserts svn's version is at least min_version.""" | 978 """Asserts svn's version is at least min_version.""" |
| 935 if cls.current_version is None: | 979 if cls.current_version is None: |
| 936 cls.current_version = cls.Capture(['--version']).split()[2] | 980 cls.current_version = cls.Capture(['--version']).split()[2] |
| 937 current_version_list = map(only_int, cls.current_version.split('.')) | 981 current_version_list = map(only_int, cls.current_version.split('.')) |
| 938 for min_ver in map(int, min_version.split('.')): | 982 for min_ver in map(int, min_version.split('.')): |
| 939 ver = current_version_list.pop(0) | 983 ver = current_version_list.pop(0) |
| 940 if ver < min_ver: | 984 if ver < min_ver: |
| 941 return (False, cls.current_version) | 985 return (False, cls.current_version) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 # revert, like for properties. | 1031 # revert, like for properties. |
| 988 if not os.path.isdir(repo_root): | 1032 if not os.path.isdir(repo_root): |
| 989 # '.' was deleted. It's not worth continuing. | 1033 # '.' was deleted. It's not worth continuing. |
| 990 return | 1034 return |
| 991 try: | 1035 try: |
| 992 SVN.Capture(['revert', file_status[1]], cwd=repo_root) | 1036 SVN.Capture(['revert', file_status[1]], cwd=repo_root) |
| 993 except subprocess2.CalledProcessError: | 1037 except subprocess2.CalledProcessError: |
| 994 if not os.path.exists(file_path): | 1038 if not os.path.exists(file_path): |
| 995 continue | 1039 continue |
| 996 raise | 1040 raise |
| OLD | NEW |