Allow remote url to be relative to manifst url

This commit is contained in:
Conley Owens 2011-09-26 16:34:01 -07:00 committed by Shawn O. Pearce
parent c4657969eb
commit db728cd866

View File

@ -14,7 +14,9 @@
# limitations under the License. # limitations under the License.
import os import os
import re
import sys import sys
import urlparse
import xml.dom.minidom import xml.dom.minidom
from git_config import GitConfig, IsId from git_config import GitConfig, IsId
@ -24,6 +26,9 @@ from error import ManifestParseError
MANIFEST_FILE_NAME = 'manifest.xml' MANIFEST_FILE_NAME = 'manifest.xml'
LOCAL_MANIFEST_NAME = 'local_manifest.xml' LOCAL_MANIFEST_NAME = 'local_manifest.xml'
urlparse.uses_relative.extend(['ssh', 'git'])
urlparse.uses_netloc.extend(['ssh', 'git'])
class _Default(object): class _Default(object):
"""Project defaults within the manifest.""" """Project defaults within the manifest."""
@ -35,16 +40,22 @@ class _XmlRemote(object):
def __init__(self, def __init__(self,
name, name,
fetch=None, fetch=None,
manifestUrl=None,
review=None): review=None):
self.name = name self.name = name
self.fetchUrl = fetch self.fetchUrl = fetch
self.manifestUrl = manifestUrl
self.reviewUrl = review self.reviewUrl = review
def ToRemoteSpec(self, projectName): def ToRemoteSpec(self, projectName):
url = self.fetchUrl url = self.fetchUrl.rstrip('/') + '/' + projectName + '.git'
while url.endswith('/'): manifestUrl = self.manifestUrl.rstrip('/')
url = url[:-1] # urljoin will get confused if there is no scheme in the base url
url += '/%s.git' % projectName # ie, if manifestUrl is of the form <hostname:port>
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
manifestUrl = 'gopher://' + manifestUrl
url = urlparse.urljoin(manifestUrl, url)
url = re.sub(r'^gopher://', '', url)
return RemoteSpec(self.name, url, self.reviewUrl) return RemoteSpec(self.name, url, self.reviewUrl)
class XmlManifest(object): class XmlManifest(object):
@ -366,7 +377,8 @@ class XmlManifest(object):
if name is None: if name is None:
s = m_url.rindex('/') + 1 s = m_url.rindex('/') + 1
remote = _XmlRemote('origin', m_url[:s]) manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
remote = _XmlRemote('origin', m_url[:s], manifestUrl)
name = m_url[s:] name = m_url[s:]
if name.endswith('.git'): if name.endswith('.git'):
@ -394,7 +406,8 @@ class XmlManifest(object):
review = node.getAttribute('review') review = node.getAttribute('review')
if review == '': if review == '':
review = None review = None
return _XmlRemote(name, fetch, review) manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
return _XmlRemote(name, fetch, manifestUrl, review)
def _ParseDefault(self, node): def _ParseDefault(self, node):
""" """