Commit 492a368f authored by wittman@chromium.org's avatar wittman@chromium.org

Fix error syncing to LKGR due to misparsing of Cygwin git-svn output.

BUG=138104
TEST=


Review URL: https://chromiumcodereview.appspot.com/10826035

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@150952 0039d316-1c4b-4281-b951-d872f2087c98
parent ac0ba33c
......@@ -390,15 +390,20 @@ class GIT(object):
except (subprocess2.CalledProcessError, ValueError):
return None
@staticmethod
def ParseGitSvnSha1(output):
"""Parses git-svn output for the first sha1."""
match = re.search(r'[0-9a-fA-F]{40}', output)
return match.group(0) if match else 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' + str(rev)], cwd=cwd).splitlines()
return lines[-1].strip() if lines else None
output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd)
return GIT.ParseGitSvnSha1(output)
except subprocess2.CalledProcessError:
return None
......
......@@ -92,6 +92,7 @@ class GitWrapperTestCase(BaseSCMTestCase):
'IsGitSvn',
'IsValidRevision',
'MatchSvnGlob',
'ParseGitSvnSha1',
'ShortBranchName',
]
# If this test fails, you should add the relevant test.
......@@ -167,6 +168,16 @@ class RealGitSvnTest(fake_repos.FakeReposTestBase):
self._capture(['reset', '--hard', 'HEAD^'])
self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1)
def testParseGitSvnSha1(self):
test_sha1 = 'a5c63ce8671922e5c59c0dea49ef4f9d4a3020c9'
expected_output = test_sha1 + '\n'
# Cygwin git-svn 1.7.9 prints extra escape sequences when run under
# TERM=xterm
cygwin_output = test_sha1 + '\n\033[?1034h'
self.assertEquals(scm.GIT.ParseGitSvnSha1(expected_output), test_sha1)
self.assertEquals(scm.GIT.ParseGitSvnSha1(cygwin_output), test_sha1)
def testGetGetSha1ForSvnRev(self):
if not self.enabled:
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment