From 2a75fdb0fc7cb79c35ab10ce679f2973db8ba2b4 Mon Sep 17 00:00:00 2001 From: "dbeam@chromium.org" Date: Wed, 15 Feb 2012 01:32:57 +0000 Subject: [PATCH] [depot_tools] Use git fetch to optimize the properly configured that use git-svn in the way 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 --- gclient_scm.py | 8 ++++++++ tests/gclient_scm_test.py | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index 2a97e896a..9f74cc57a 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -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) diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index c0c872870..581b2734b 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -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.