From 051c88b9c0c2977a5a99ca199033c95ed5ba242e Mon Sep 17 00:00:00 2001 From: "dbeam@chromium.org" Date: Thu, 22 Dec 2011 00:23:03 +0000 Subject: [PATCH] [depot_tools] Disabling new git checkouts with safesync_urls until fixed. R=maruel@chromium.org TEST=gclient sync a freshly configured client. BUG=106015 Review URL: http://codereview.chromium.org/8994016 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@115452 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 32 ++++++++++++++++++----------- gclient_scm.py | 43 +++++++++++++++++++++++++-------------- tests/gclient_scm_test.py | 12 ++++++++--- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/gclient.py b/gclient.py index c804186e8..041dc3690 100644 --- a/gclient.py +++ b/gclient.py @@ -920,18 +920,7 @@ solutions = [ if not s.managed: self._options.revisions.append('%s@unmanaged' % s.name) elif s.safesync_url: - handle = urllib.urlopen(s.safesync_url) - rev = handle.read().strip() - handle.close() - scm = gclient_scm.CreateSCM(s.url, s.root.root_dir, s.name) - safe_rev = scm.GetUsableRev(rev=rev, options=self._options) - if not safe_rev: - raise gclient_utils.Error( - 'Despite our best attempts, we couldn\'t find a useful\n' - 'safesync_url revision for you.') - if self._options.verbose: - print('Using safesync_url revision: %s.\n' % safe_rev) - self._options.revisions.append('%s@%s' % (s.name, safe_rev)) + self._ApplySafeSyncRev(dep=s) if not self._options.revisions: return revision_overrides solutions_names = [s.name for s in self.dependencies] @@ -950,6 +939,25 @@ solutions = [ index += 1 return revision_overrides + def _ApplySafeSyncRev(self, dep): + """Finds a valid revision from the content of the safesync_url and apply it + by appending revisions to the revision list. Throws if revision appears to + be invalid for the given |dep|.""" + assert len(dep.safesync_url) > 0 + handle = urllib.urlopen(dep.safesync_url) + rev = handle.read().strip() + handle.close() + if not rev: + raise gclient_utils.Error( + 'It appears your safesync_url (%s) is not working properly\n' + '(as it returned an empty response). Check your config.' % + dep.safesync_url) + scm = gclient_scm.CreateSCM(dep.url, dep.root.root_dir, dep.name) + safe_rev = scm.GetUsableRev(rev=rev, options=self._options) + if self._options.verbose: + print('Using safesync_url revision: %s.\n' % safe_rev) + self._options.revisions.append('%s@%s' % (dep.name, safe_rev)) + def RunOnDeps(self, command, args): """Runs a command on each dependency in a client and its dependencies. diff --git a/gclient_scm.py b/gclient_scm.py index 0b21dce99..211aa4737 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -489,26 +489,39 @@ class GitWrapper(SCMWrapper): If SCM is git-svn and the head revision is less than |rev|, git svn fetch will be called on the source.""" sha1 = None - # As an optimization, only verify an SVN revision as [0-9]{1,6} for now to - # avoid making a network request. - if (scm.GIT.IsGitSvn(cwd=self.checkout_path) and - rev.isdigit() and len(rev) < 7): - local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path) - if not local_head or local_head < int(rev): - if options.verbose: - print('Running git svn fetch. This might take a while.\n') - scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) - sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) + # Handles an SVN rev. As an optimization, only verify an SVN revision as + # [0-9]{1,6} for now to avoid making a network request. + if rev.isdigit() and len(rev) < 7: + # If the content of the safesync_url appears to be an SVN rev and the + # URL of the source appears to be git, we can only attempt to find out + # if a revision is useful after we've cloned the original URL, so just + # ignore for now. + if (os.path.isdir(self.checkout_path) and + 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): + if options.verbose: + print('Running git svn fetch. This might take a while.\n') + scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) + sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) + if not sha1: + raise gclient_utils.Error( + ( 'It appears that either your git-svn remote is incorrectly\n' + 'configured or the revision in your safesync_url is\n' + 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' + 'corresponding git hash for SVN rev %s.' ) % rev) elif scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): sha1 = rev + if not sha1: raise gclient_utils.Error( - ( '%s is not a value hash. Safesync URLs with a git checkout\n' - 'currently require a git-svn remote or a safesync_url that\n' - 'provides git sha1s. Please add a git-svn remote or change\n' - 'your safesync_url. For more info, see:\n' + ( 'We could not find a valid hash for safesync_url response "%s".\n' + 'Safesync URLs with a git checkout currently require a git-svn\n' + 'remote or a safesync_url that provides git sha1s. Please add a\n' + 'git-svn remote or change your safesync_url. For more info, see:\n' 'http://code.google.com/p/chromium/wiki/UsingNewGit' - '#Initial_checkout') % rev) + '#Initial_checkout' ) % rev) + return sha1 def FullUrlForRelativeUrl(self, url): diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index ac13c108b..41f4281fd 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -1004,13 +1004,13 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase): self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 ).AndReturn(True) - gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev='1' - ).AndReturn(False) self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( ).AndReturn(False) + gclient_scm.scm.os.path.isdir(self.base_path).AndReturn(True) + self.mox.ReplayAll() git_scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, @@ -1019,7 +1019,7 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase): # the LKGR gets flipped to git sha1's some day). self.assertEquals(git_scm.GetUsableRev(self.fake_hash_1, options), self.fake_hash_1) - # An SVN rev with a purely git repo should raise an exception. + # An SVN rev with an existing purely git repo should raise an exception. self.assertRaises(gclient_scm.gclient_utils.Error, git_scm.GetUsableRev, '1', options) @@ -1054,10 +1054,16 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase): gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big ).AndReturn(False) + gclient_scm.os.path.isdir(self.base_path).AndReturn(False) + gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) + self.mox.ReplayAll() 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. + 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),