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
experimental/szager/collated-output
szager@chromium.org 13 years ago
parent 312a6a4e7a
commit c51def3ff4

@ -590,7 +590,8 @@ class GitWrapper(SCMWrapper):
print('Running git svn fetch. This might take a while.\n') print('Running git svn fetch. This might take a while.\n')
scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path)
try: 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: except gclient_utils.Error, e:
sha1 = e.message sha1 = e.message
print('\nWarning: Could not find a git revision with accurate\n' print('\nWarning: Could not find a git revision with accurate\n'

@ -402,10 +402,23 @@ class GIT(object):
if not GIT.IsGitSvn(cwd=cwd): if not GIT.IsGitSvn(cwd=cwd):
return None return None
try: try:
git_svn_rev = GIT.Capture( output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd)
['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).rstrip() 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: if not git_svn_rev:
return None return None
try:
output = GIT.Capture( output = GIT.Capture(
['rev-list', '--ancestry-path', '--reverse', ['rev-list', '--ancestry-path', '--reverse',
'--grep', 'SVN changes up to revision [0-9]*', '--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( gclient_scm.scm.GIT.GetGitSvnHeadRev(cwd=self.base_path).MultipleTimes(
).AndReturn(2) ).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. # 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) ).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) ).MultipleTimes().AndReturn(self.fake_hash_2)
# Ensure that we call git svn fetch if our LKGR is > the git-svn HEAD rev. # 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', 'current_version',
'FetchUpstreamTuple', 'FetchUpstreamTuple',
'GenerateDiff', 'GenerateDiff',
'GetBlessedSha1ForSvnRev',
'GetBranch', 'GetBranch',
'GetBranchRef', 'GetBranchRef',
'GetCheckoutRoot', 'GetCheckoutRoot',

Loading…
Cancel
Save