Commit e6f78352 authored by msb@chromium.org's avatar msb@chromium.org

gclient: git relative url implementation

Redo relative url implementation per maruel's comments here:
http://codereview.chromium.org/500015

Instead of adding an option, implement relative urls differently for
git urls.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@36126 0039d316-1c4b-4281-b951-d872f2087c98
parent 32906d1b
......@@ -518,11 +518,6 @@ class GClient(object):
solution_deps_content[solution["name"]],
custom_vars)
local_scope = {}
var = self._VarImpl(custom_vars, local_scope)
global_scope = {"From": self.FromImpl, "Var": var.Lookup, "deps_os": {}}
exec(solution_deps_content[solution["name"]], global_scope, local_scope)
# If a line is in custom_deps, but not in the solution, we want to append
# this line to the solution.
if "custom_deps" in solution:
......@@ -560,10 +555,10 @@ class GClient(object):
if path[0] != "/":
raise gclient_utils.Error(
"relative DEPS entry \"%s\" must begin with a slash" % d)
if local_scope.get('use_relative_urls2'):
url = gclient_utils.FullUrlFromRelative2(solution["url"], url)
else:
url = gclient_utils.FullUrlFromRelative(solution["url"], url)
# Create a scm just to query the full url.
scm = gclient_scm.CreateSCM(solution["url"], self._root_dir,
None)
url = scm.FullUrlForRelativeUrl(url)
if d in deps and deps[d] != url:
raise gclient_utils.Error(
"Solutions have conflicting versions of dependency \"%s\"" % d)
......
......@@ -249,6 +249,12 @@ class GitWrapper(SCMWrapper, scm.GIT):
files = self._Run(['diff', '--name-only', merge_base]).split()
file_list.extend([os.path.join(self.checkout_path, f) for f in files])
def FullUrlForRelativeUrl(self, url):
# Strip from last '/'
# Equivalent to unix basename
base_url = self.url
return base_url[:base_url.rfind('/')] + url
def _CheckMinVersion(self, min_version):
def only_int(val):
if val.isdigit():
......@@ -528,3 +534,7 @@ class SVNWrapper(SCMWrapper, scm.SVN):
# There's no file list to retrieve.
else:
self.RunAndGetFileList(options, command, path, file_list)
def FullUrlForRelativeUrl(self, url):
# Find the forth '/' and strip from there. A bit hackish.
return '/'.join(self.url.split('/')[:4]) + url
......@@ -71,17 +71,6 @@ def SplitUrlRevision(url):
return tuple(components)
def FullUrlFromRelative(base_url, url):
# Find the forth '/' and strip from there. A bit hackish.
return '/'.join(base_url.split('/')[:4]) + url
def FullUrlFromRelative2(base_url, url):
# Strip from last '/'
# Equivalent to unix basename
return base_url[:base_url.rfind('/')] + url
def ParseXML(output):
try:
return xml.dom.minidom.parseString(output)
......
......@@ -66,8 +66,8 @@ class SVNWrapperTestCase(BaseTestCase):
members = [
'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
'CaptureStatus', 'DiffItem', 'GenerateDiff', 'GetCheckoutRoot',
'GetEmail', 'GetFileProperty', 'IsMoved', 'ReadSimpleAuth', 'Run',
'RunAndFilterOutput', 'RunAndGetFileList',
'GetEmail', 'GetFileProperty', 'FullUrlForRelativeUrl', 'IsMoved',
'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList',
'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
]
......@@ -81,6 +81,22 @@ class SVNWrapperTestCase(BaseTestCase):
exception_msg = 'Unsupported scm %(scm_name)s' % kwargs
self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
def testSVNFullUrlForRelativeUrl(self):
self.url = 'svn://a/b/c/d'
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
def testGITFullUrlForRelativeUrl(self):
self.url = 'git://a/b/c/d'
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap')
def testRunCommandException(self):
options = self.Options(verbose=False)
file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
......@@ -361,10 +377,11 @@ from :3
def testDir(self):
members = [
'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple',
'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot',
'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch',
'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName',
'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
'FullUrlForRelativeUrl', 'GenerateDiff', 'GetBranch', 'GetBranchRef',
'GetCheckoutRoot', 'GetDifferentFiles', 'GetEmail', 'GetPatchName',
'GetSVNBranch', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput',
'ShortBranchName', 'RunCommand',
'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
]
......
......@@ -47,7 +47,6 @@ class GClientBaseTestCase(BaseTestCase):
self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite')
self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall')
self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory')
self.mox.StubOutWithMock(gclient.gclient_utils, 'FullUrlFromRelative')
# Mock them to be sure nothing bad happens.
self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Capture')
self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureInfo')
......@@ -798,13 +797,15 @@ deps_os = {
scm_wrapper_src)
scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, [])
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/deps/third_party/cygwin@3248'
).AndReturn(cygwin_path)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
None).AndReturn(scm_wrapper_src2)
scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248'
).AndReturn(cygwin_path)
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/deps/third_party/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
None).AndReturn(scm_wrapper_src2)
scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(
webkit_path, self.root_dir, 'foo/third_party/WebKit'
......@@ -912,9 +913,10 @@ deps = {
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/bar/WebKit',
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir, None
).AndReturn(scm_wrapper_src)
scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(
webkit_path, self.root_dir, 'foo/third_party/WebKit'
......@@ -975,9 +977,10 @@ deps = {
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/bar_custom/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
None).AndReturn(scm_wrapper_src)
scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(webkit_path, self.root_dir,
'foo/third_party/WebKit').AndReturn(gclient.gclient_scm.CreateSCM)
......
......@@ -15,8 +15,7 @@ class GclientUtilsUnittest(SuperMoxTestBase):
def testMembersChanged(self):
members = [
'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite',
'FindGclientRoot',
'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText',
'FindGclientRoot', 'GetNamedNodeText',
'GetNodeNamedAttributeText', 'IsUsingGit', 'PathDifference',
'ParseXML', 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',
'SubprocessCall', 'SubprocessCallAndFilter', 'errno', 'logging', 'os',
......@@ -138,18 +137,6 @@ class SplitUrlRevisionTestCase(SuperMoxTestBase):
self.assertEquals(out_url, url)
class FullUrlFromRelative(SuperMoxTestBase):
def testFullUrlFromRelative(self):
base_url = 'svn://a/b/c/d'
full_url = gclient_utils.FullUrlFromRelative(base_url, '/crap')
self.assertEqual(full_url, 'svn://a/b/crap')
def testFullUrlFromRelative2(self):
base_url = 'svn://a/b/c/d'
full_url = gclient_utils.FullUrlFromRelative2(base_url, '/crap')
self.assertEqual(full_url, 'svn://a/b/c/crap')
if __name__ == '__main__':
import unittest
unittest.main()
......
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