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