Chromium Code Reviews| Index: scm.py |
| =================================================================== |
| --- scm.py (revision 108803) |
| +++ scm.py (working copy) |
| @@ -379,6 +379,37 @@ |
| root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip() |
| return os.path.abspath(os.path.join(cwd, root)) |
| + @staticmethod |
| + def GetGitSvnHeadRev(cwd): |
| + """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.
|
| + try: |
| + output = GIT.Capture(['svn', 'info'], cwd=cwd) |
| + 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
|
| + return int(match.group(1)) if match else None |
| + except (subprocess2.CalledProcessError, ValueError): |
| + return None |
| + |
| + @staticmethod |
| + def GetSha1ForSvnRev(cwd, rev): |
| + """Returns a corresponding git sha1 for a SVN revision.""" |
| + if not GIT.IsGitSvn(cwd=cwd): |
| + return None |
| + try: |
| + lines = GIT.Capture( |
| + ['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
|
| + return lines[-1].strip() if len(lines) else None |
| + except subprocess2.CalledProcessError: |
| + return None |
| + |
| + @staticmethod |
| + 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.
|
| + """Verifies the revision is a proper git revision.""" |
| + try: |
| + GIT.Capture(['rev-parse', rev], cwd=cwd) |
| + return True |
| + except subprocess2.CalledProcessError: |
| + return False |
| + |
| @classmethod |
| def AssertVersion(cls, min_version): |
| """Asserts git's version is at least min_version.""" |
| @@ -929,6 +960,18 @@ |
| directory = parent |
| return GetCasedPath(directory) |
| + @staticmethod |
| + def VerifyRevisionFormat(cwd, rev, url=None): |
| + """Verifies the revision looks like an SVN revision""" |
| + try: |
| + if url: |
| + 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.
|
| + else: |
| + SVN.Capture(['info', '-r', rev]) |
| + return True |
| + except subprocess2.CalledProcessError: |
| + return False |
| + |
| @classmethod |
| def AssertVersion(cls, min_version): |
| """Asserts svn's version is at least min_version.""" |