Commit c51def3f authored by szager@chromium.org's avatar szager@chromium.org

Restore previous behavior of GetSha1ForSvnRev, so unit tests pass.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@161909 0039d316-1c4b-4281-b951-d872f2087c98
parent 312a6a4e
......@@ -590,7 +590,8 @@ class GitWrapper(SCMWrapper):
print('Running git svn fetch. This might take a while.\n')
scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path)
try:
sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev)
sha1 = scm.GIT.GetBlessedSha1ForSvnRev(
cwd=self.checkout_path, rev=rev)
except gclient_utils.Error, e:
sha1 = e.message
print('\nWarning: Could not find a git revision with accurate\n'
......
......@@ -402,10 +402,23 @@ class GIT(object):
if not GIT.IsGitSvn(cwd=cwd):
return None
try:
git_svn_rev = GIT.Capture(
['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).rstrip()
if not git_svn_rev:
return None
output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd)
return GIT.ParseGitSvnSha1(output)
except subprocess2.CalledProcessError:
return None
@staticmethod
def GetBlessedSha1ForSvnRev(cwd, rev):
"""Returns a git commit hash from the master branch history that has
accurate .DEPS.git and git submodules. To understand why this is more
complicated than a simple call to `git svn find-rev`, refer to:
http://www.chromium.org/developers/how-tos/git-repo
"""
git_svn_rev = GIT.GetSha1ForSvnRev(cwd, rev)
if not git_svn_rev:
return None
try:
output = GIT.Capture(
['rev-list', '--ancestry-path', '--reverse',
'--grep', 'SVN changes up to revision [0-9]*',
......
......@@ -1096,11 +1096,12 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
gclient_scm.scm.GIT.GetGitSvnHeadRev(cwd=self.base_path).MultipleTimes(
).AndReturn(2)
self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'GetSha1ForSvnRev', True)
self.mox.StubOutWithMock(
gclient_scm.scm.GIT, 'GetBlessedSha1ForSvnRev', True)
# r1 -> first fake hash, r3 -> second fake hash.
gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='1'
gclient_scm.scm.GIT.GetBlessedSha1ForSvnRev(cwd=self.base_path, rev='1'
).AndReturn(self.fake_hash_1)
gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='3'
gclient_scm.scm.GIT.GetBlessedSha1ForSvnRev(cwd=self.base_path, rev='3'
).MultipleTimes().AndReturn(self.fake_hash_2)
# Ensure that we call git svn fetch if our LKGR is > the git-svn HEAD rev.
......
......@@ -79,6 +79,7 @@ class GitWrapperTestCase(BaseSCMTestCase):
'current_version',
'FetchUpstreamTuple',
'GenerateDiff',
'GetBlessedSha1ForSvnRev',
'GetBranch',
'GetBranchRef',
'GetCheckoutRoot',
......
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