Commit 2a75fdb0 authored by dbeam@chromium.org's avatar dbeam@chromium.org

[depot_tools] Use git fetch to optimize the properly configured that use git-svn

in the way <http://code.google.com/p/chromium/wiki/UsingNewGit#Initial_checkout>
describes.

R=maruel@chromium.org
TEST=gclient sync with safesync_url is faster.
BUG=109184


Review URL: http://codereview.chromium.org/9379005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@121988 0039d316-1c4b-4281-b951-d872f2087c98
parent 93567043
......@@ -514,6 +514,14 @@ class GitWrapper(SCMWrapper):
scm.GIT.IsGitSvn(cwd=self.checkout_path)):
local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path)
if not local_head or local_head < int(rev):
try:
logging.debug('Looking for git-svn configuration optimizations.')
if scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
cwd=self.checkout_path):
scm.GIT.Capture(['fetch'], cwd=self.checkout_path)
except subprocess2.CalledProcessError:
logging.debug('git config --get svn-remote.svn.fetch failed, '
'ignoring possible optimization.')
if options.verbose:
print('Running git svn fetch. This might take a while.\n')
scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path)
......
......@@ -1188,10 +1188,17 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='1'
).AndReturn(self.fake_hash_1)
gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='3'
).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.
self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
cwd=self.base_path).AndReturn('blah')
gclient_scm.scm.GIT.Capture(['fetch'], cwd=self.base_path)
gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path)
error = subprocess2.CalledProcessError(1, 'cmd', '/cwd', 'stdout', 'stderr')
gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
cwd=self.base_path).AndRaise(error)
gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path)
self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
......@@ -1211,15 +1218,20 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
# Without an existing checkout, this should fail. TODO(dbeam) Fix this.
# Without an existing checkout, this should fail.
# TODO(dbeam) Fix this. http://crbug.com/109184
self.assertRaises(gclient_scm.gclient_utils.Error,
git_svn_scm.GetUsableRev, '1', options)
# Given an SVN revision with a git-svn checkout, it should be translated to
# a git sha1 and be usable.
self.assertEquals(git_svn_scm.GetUsableRev('1', options),
self.fake_hash_1)
# Our fake HEAD rev is r2, so this should call git svn fetch to get more
# revs (pymox will complain if this doesn't happen).
# Our fake HEAD rev is r2, so this should call git fetch and git svn fetch
# to get more revs (pymox will complain if this doesn't happen). We mock an
# optimized checkout the first time, so this run should call git fetch.
self.assertEquals(git_svn_scm.GetUsableRev('3', options),
self.fake_hash_2)
# The time we pretend we're not optimized, so no git fetch should fire.
self.assertEquals(git_svn_scm.GetUsableRev('3', options),
self.fake_hash_2)
# Given a git sha1 with a git-svn checkout, it should be used as is.
......
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