Fix changeset fetching

This change adds support for fetching over the anonymous git and
authenticated SSH protocols, and it also makes sure that we follow URLs
specified by the download plugin (they might differ from the server's
address even for anonymous HTTP).

Also see https://storyboard.openstack.org/#!/story/294 .

Change-Id: Iafb7ae63147fc7a70ab63a9d6f61617b87e65ac9
This commit is contained in:
Jan Kundrát 2014-10-22 21:56:06 +02:00 committed by James E. Blair
parent ae8c3ad37c
commit bb4c83bf8d
1 changed files with 22 additions and 5 deletions

View File

@ -474,18 +474,35 @@ class SyncChangeTask(Task):
for remote_commit, remote_revision in remote_change.get('revisions', {}).items():
revision = session.getRevisionByCommit(remote_commit)
# TODO: handle multiple parents
url = sync.app.config.url + change.project.name
if 'anonymous http' in remote_revision['fetch']:
ref = remote_revision['fetch']['anonymous http']['ref']
if 'git' in remote_revision['fetch']:
ref = remote_revision['fetch']['git']['ref']
url = remote_revision['fetch']['git']['url']
auth = False
else:
elif 'anonymous http' in remote_revision['fetch']:
ref = remote_revision['fetch']['anonymous http']['ref']
url = remote_revision['fetch']['anonymous http']['url']
auth = False
elif 'http' in remote_revision['fetch']:
auth = True
ref = remote_revision['fetch']['http']['ref']
url = list(urlparse.urlsplit(url))
url = list(urlparse.urlsplit(sync.app.config.url + change.project.name))
url[1] = '%s:%s@%s' % (
urllib.quote_plus(sync.app.config.username),
urllib.quote_plus(sync.app.config.password), url[1])
url = urlparse.urlunsplit(url)
elif 'ssh' in remote_revision['fetch']:
ref = remote_revision['fetch']['ssh']['ref']
url = remote_revision['fetch']['ssh']['url']
auth = False
else:
if len(remote_revision['fetch']):
errMessage = 'Don\'t know how to download changes. ' \
'Server offered these schemes, but Gertty doesn\'t support any of them: %s' \
% ', '.join(remote_revision['fetch'].keys())
else:
errMessage = 'The server is missing the download-commands plugin. ' \
'Don\'t know how to download revisions.'
raise Exception(errMessage)
if (not revision) or self.force_fetch:
fetches[url].append('+%(ref)s:%(ref)s' % dict(ref=ref))
if not revision: