From 5479310d759a7577c550cbcc0d783fd3a34eab37 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sun, 29 Mar 2015 02:20:03 +0200 Subject: [PATCH] Add config option for git clone URL This commit adds a new config option 'git-url', where the base URL can be specified to anything recognised by git-clone: https://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS This is useful if the values provided by gerrit are incorrect, or if you have access to a gerrit mirror closer to you. Change-Id: I35ee5540aad2f27125ec15e6e933ac1ad3f3050e --- examples/reference-gertty.yaml | 4 ++++ gertty/config.py | 5 +++++ gertty/gitrepo.py | 2 +- gertty/sync.py | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/reference-gertty.yaml b/examples/reference-gertty.yaml index 0d74d7a..3705f12 100644 --- a/examples/reference-gertty.yaml +++ b/examples/reference-gertty.yaml @@ -32,6 +32,10 @@ servers: # Gertty will not modify them unless you tell it to, and even then the # normal git protections against losing work remain in place. [required] # git-root: ~/git/ +# The URL to clone git repos. By default, /p/ is used. For a list +# of valid URLs, see: +# https://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS +# git-url: ssh://user@example.org:29418 # The location of Gertty's sqlite database. If you have more than one # server, you should specify a dburi for any additional servers. # By default a SQLite database called ~/.gertty.db is used. diff --git a/gertty/config.py b/gertty/config.py index eeedf39..4b9737c 100644 --- a/gertty/config.py +++ b/gertty/config.py @@ -46,6 +46,7 @@ class ConfigSchema(object): 'ssl-ca-path': str, 'dburi': str, v.Required('git-root'): str, + 'git-url': str, 'log-file': str, 'socket': str, 'auth-type': str, @@ -177,6 +178,10 @@ class Config(object): # And this is to allow Git callouts os.environ['GIT_SSL_CAINFO'] = self.ssl_ca_path self.git_root = os.path.expanduser(server['git-root']) + git_url = server.get('git-url', self.url + 'p/') + if not git_url.endswith('/'): + git_url += '/' + self.git_url = git_url self.dburi = server.get('dburi', 'sqlite:///' + os.path.expanduser('~/.gertty.db')) socket_path = server.get('socket', '~/.gertty.sock') diff --git a/gertty/gitrepo.py b/gertty/gitrepo.py index 8587fe7..9cc43e6 100644 --- a/gertty/gitrepo.py +++ b/gertty/gitrepo.py @@ -517,4 +517,4 @@ def get_repo(project_name, config): local_path = os.path.join(config.git_root, project_name) local_root = os.path.abspath(config.git_root) assert os.path.commonprefix((local_root, local_path)) == local_root - return Repo(config.url+'p/'+project_name, local_path) + return Repo(config.git_url + project_name, local_path) diff --git a/gertty/sync.py b/gertty/sync.py index 8e575a1..5f8539f 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -607,6 +607,7 @@ 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.git_url + change.project.name if 'anonymous http' in remote_revision['fetch']: ref = remote_revision['fetch']['anonymous http']['ref'] url = remote_revision['fetch']['anonymous http']['url']