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 """Get the most recently pulled git-svn revision.""" | |
|
M-A Ruel
2011/11/08 14:29:20
"Gets", you see the deal. :)
Dan Beam
2011/11/09 10:31:15
Done.
| |
| 385 try: | |
| 386 output = GIT.Capture(['svn', 'info'], cwd=cwd) | |
| 387 match = re.search('\nRevision: ([0-9]+)\n', output) | |
|
M-A Ruel
2011/11/08 14:29:20
you should use ^$ instead of \n ? e.g. :
re.search
Dan Beam
2011/11/09 10:31:15
Done. (tried this a couple times before and it jus
| |
| 388 return int(match.group(1)) if match else None | |
| 389 except (subprocess2.CalledProcessError, ValueError): | |
| 390 return None | |
| 391 | |
| 392 @staticmethod | |
| 393 def GetSha1ForSvnRev(cwd, rev): | |
| 394 """Returns a corresponding git sha1 for a SVN revision.""" | |
| 395 if not GIT.IsGitSvn(cwd=cwd): | |
| 396 return None | |
| 397 try: | |
| 398 lines = GIT.Capture( | |
| 399 ['svn', 'find-rev', 'r' + rev], cwd=cwd).splitlines(True) | |
|
M-A Ruel
2011/11/08 14:29:20
Why True?
What if isinstance(rev, int) ?
Dan Beam
2011/11/09 10:31:15
Oh, guess I didn't need that, you're right. Thoug
| |
| 400 return lines[-1].strip() if len(lines) else None | |
| 401 except subprocess2.CalledProcessError: | |
| 402 return None | |
| 403 | |
| 404 @staticmethod | |
| 405 def VerifyRevisionFormat(cwd, rev): | |
|
M-A Ruel
2011/11/08 14:29:20
I'd rename the function, you are not verifying the
Dan Beam
2011/11/09 10:31:15
Done.
| |
| 406 """Verifies the revision is a proper git revision.""" | |
| 407 try: | |
| 408 GIT.Capture(['rev-parse', rev], cwd=cwd) | |
| 409 return True | |
| 410 except subprocess2.CalledProcessError: | |
| 411 return False | |
| 412 | |
| 382 @classmethod | 413 @classmethod |
| 383 def AssertVersion(cls, min_version): | 414 def AssertVersion(cls, min_version): |
| 384 """Asserts git's version is at least min_version.""" | 415 """Asserts git's version is at least min_version.""" |
| 385 if cls.current_version is None: | 416 if cls.current_version is None: |
| 386 cls.current_version = cls.Capture(['--version']).split()[-1] | 417 cls.current_version = cls.Capture(['--version']).split()[-1] |
| 387 current_version_list = map(only_int, cls.current_version.split('.')) | 418 current_version_list = map(only_int, cls.current_version.split('.')) |
| 388 for min_ver in map(int, min_version.split('.')): | 419 for min_ver in map(int, min_version.split('.')): |
| 389 ver = current_version_list.pop(0) | 420 ver = current_version_list.pop(0) |
| 390 if ver < min_ver: | 421 if ver < min_ver: |
| 391 return (False, cls.current_version) | 422 return (False, cls.current_version) |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 info = SVN.CaptureInfo(parent) | 953 info = SVN.CaptureInfo(parent) |
| 923 if (info['Repository Root'] != cur_dir_repo_root or | 954 if (info['Repository Root'] != cur_dir_repo_root or |
| 924 info['URL'] != os.path.dirname(url)): | 955 info['URL'] != os.path.dirname(url)): |
| 925 break | 956 break |
| 926 url = info['URL'] | 957 url = info['URL'] |
| 927 except subprocess2.CalledProcessError: | 958 except subprocess2.CalledProcessError: |
| 928 break | 959 break |
| 929 directory = parent | 960 directory = parent |
| 930 return GetCasedPath(directory) | 961 return GetCasedPath(directory) |
| 931 | 962 |
| 963 @staticmethod | |
| 964 def VerifyRevisionFormat(cwd, rev, url=None): | |
| 965 """Verifies the revision looks like an SVN revision""" | |
| 966 try: | |
| 967 if url: | |
| 968 SVN.Capture(['info', '-r', rev, url]) | |
|
M-A Ruel
2011/11/08 14:29:20
If it is an url, it should simply use the format u
Dan Beam
2011/11/09 10:31:15
Done.
| |
| 969 else: | |
| 970 SVN.Capture(['info', '-r', rev]) | |
| 971 return True | |
| 972 except subprocess2.CalledProcessError: | |
| 973 return False | |
| 974 | |
| 932 @classmethod | 975 @classmethod |
| 933 def AssertVersion(cls, min_version): | 976 def AssertVersion(cls, min_version): |
| 934 """Asserts svn's version is at least min_version.""" | 977 """Asserts svn's version is at least min_version.""" |
| 935 if cls.current_version is None: | 978 if cls.current_version is None: |
| 936 cls.current_version = cls.Capture(['--version']).split()[2] | 979 cls.current_version = cls.Capture(['--version']).split()[2] |
| 937 current_version_list = map(only_int, cls.current_version.split('.')) | 980 current_version_list = map(only_int, cls.current_version.split('.')) |
| 938 for min_ver in map(int, min_version.split('.')): | 981 for min_ver in map(int, min_version.split('.')): |
| 939 ver = current_version_list.pop(0) | 982 ver = current_version_list.pop(0) |
| 940 if ver < min_ver: | 983 if ver < min_ver: |
| 941 return (False, cls.current_version) | 984 return (False, cls.current_version) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 # revert, like for properties. | 1030 # revert, like for properties. |
| 988 if not os.path.isdir(repo_root): | 1031 if not os.path.isdir(repo_root): |
| 989 # '.' was deleted. It's not worth continuing. | 1032 # '.' was deleted. It's not worth continuing. |
| 990 return | 1033 return |
| 991 try: | 1034 try: |
| 992 SVN.Capture(['revert', file_status[1]], cwd=repo_root) | 1035 SVN.Capture(['revert', file_status[1]], cwd=repo_root) |
| 993 except subprocess2.CalledProcessError: | 1036 except subprocess2.CalledProcessError: |
| 994 if not os.path.exists(file_path): | 1037 if not os.path.exists(file_path): |
| 995 continue | 1038 continue |
| 996 raise | 1039 raise |
| OLD | NEW |