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

gclient: fix another bug where ssh urls weren't parsed correctly

ssh://test@example.com wasn't being parsed correctly for revinfo.

Fixed by factoring out all code which splits url into a base_url
and revision.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@31910 0039d316-1c4b-4281-b951-d872f2087c98
parent d5800f19
......@@ -809,18 +809,18 @@ class GClient(object):
# Inner helper to generate base url and rev tuple (including honoring
# |revision_overrides|)
def GetURLAndRev(name, original_url):
if original_url.find("@") < 0:
revision, url = gclient_utils.SplitUrlRevision(original_url)
if not revision:
if revision_overrides.has_key(name):
return (original_url, revision_overrides[name])
return (url, revision_overrides[name])
else:
scm = gclient_scm.CreateSCM(solution["url"], self._root_dir, name)
return (original_url, scm.revinfo(self._options, [], None))
return (url, scm.revinfo(self._options, [], None))
else:
url_components = original_url.split("@")
if revision_overrides.has_key(name):
return (url_components[0], revision_overrides[name])
return (url, revision_overrides[name])
else:
return (url_components[0], url_components[1])
return (url, revision)
# Run on the base solutions first.
for solution in solutions:
......
......@@ -129,23 +129,16 @@ class GitWrapper(SCMWrapper):
if args:
raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
if self.url.startswith('ssh:'):
# Make sure ssh://test@example.com/test.git@stable works
regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\.]+)(?:@([\w/]+))?"
components = re.search(regex, self.url).groups()
else:
components = self.url.split("@")
url = components[0]
revision = None
url, revision = gclient_utils.SplitUrlRevision(self.url)
rev_str = ""
if options.revision:
revision = options.revision
elif len(components) == 2:
revision = components[1]
# Override the revision number.
revision = str(options.revision)
if revision:
url = '%s@%s' % (url, revision)
rev_str = ' at %s' % revision
if options.verbose:
rev_str = ""
if revision:
rev_str = ' at %s' % revision
print("\n_____ %s%s" % (self.relpath, rev_str))
if not os.path.exists(self.checkout_path):
......@@ -269,21 +262,16 @@ class SVNWrapper(SCMWrapper):
if args:
raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
url = self.url
components = url.split("@")
revision = None
url, revision = gclient_utils.SplitUrlRevision(self.url)
base_url = url
forced_revision = False
rev_str = ""
if options.revision:
# Override the revision number.
url = '%s@%s' % (components[0], str(options.revision))
revision = options.revision
forced_revision = True
elif len(components) == 2:
revision = components[1]
forced_revision = True
rev_str = ""
revision = str(options.revision)
if revision:
forced_revision = True
url = '%s@%s' % (url, revision)
rev_str = ' at %s' % revision
if not os.path.exists(checkout_path):
......@@ -309,7 +297,7 @@ class SVNWrapper(SCMWrapper):
revision = str(from_info_live['Revision'])
rev_str = ' at %s' % revision
if from_info['URL'] != components[0]:
if from_info['URL'] != base_url:
to_info = CaptureSVNInfo(url, '.')
if not to_info.get('Repository Root') or not to_info.get('UUID'):
# The url is invalid or the server is not accessible, it's safer to bail
......
......@@ -14,6 +14,7 @@
import errno
import os
import re
import stat
import subprocess
import sys
......@@ -24,6 +25,19 @@ import xml.parsers.expat
## Generic utils
def SplitUrlRevision(url):
"""Splits url and returns a two-tuple: url, rev"""
if url.startswith('ssh:'):
# Make sure ssh://test@example.com/test.git@stable works
regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\.]+)(?:@([\w/]+))?"
components = re.search(regex, url).groups()
else:
components = url.split("@")
if len(components) == 1:
components += [None]
return tuple(components)
def ParseXML(output):
try:
return xml.dom.minidom.parseString(output)
......
......@@ -46,6 +46,35 @@ class SubprocessCallAndFilterTestCase(SuperMoxTestBase):
self.assertEquals(capture_list, ['cc', 'dd'])
class SplitUrlRevisionTestCase(SuperMoxTestBase):
def testSSHUrl(self):
url = "ssh://test@example.com/test.git"
rev = "ac345e52dc"
out_url, out_rev = gclient_utils.SplitUrlRevision(url)
self.assertEquals(out_rev, None)
self.assertEquals(out_url, url)
out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev))
self.assertEquals(out_rev, rev)
self.assertEquals(out_url, url)
url = "ssh://example.com/test.git"
out_url, out_rev = gclient_utils.SplitUrlRevision(url)
self.assertEquals(out_rev, None)
self.assertEquals(out_url, url)
out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev))
self.assertEquals(out_rev, rev)
self.assertEquals(out_url, url)
def testSVNUrl(self):
url = "svn://example.com/test"
rev = "ac345e52dc"
out_url, out_rev = gclient_utils.SplitUrlRevision(url)
self.assertEquals(out_rev, None)
self.assertEquals(out_url, url)
out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev))
self.assertEquals(out_rev, rev)
self.assertEquals(out_url, url)
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