From 7aad6d240e2041c79944c52a1c12735c53114dc1 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 6 Apr 2016 23:29:22 +0300 Subject: git-gerrit-mirror: Allow to create more than one mirror of the same host. Sometimes different downstream projects may need different mirrors of the same upstream tree. So, just allow to have different mirroring entries for the same host, differentiated with "#slug". Change-Id: I8a2edd0a58e22965ab896d3c5839623b0f844840 --- git-gerrit-mirror | 15 +++++++++++++-- mirror.conf.sample | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/git-gerrit-mirror b/git-gerrit-mirror index c0b0d3e..4bc70d0 100755 --- a/git-gerrit-mirror +++ b/git-gerrit-mirror @@ -241,7 +241,7 @@ def clone_repos(host, basedir, projects): log.info("cd'ing to %s", dir) os.chdir(dir) # --depth=1 - cmd = "git clone --mirror %s/%s.git" % (host, p) + cmd = "git clone --mirror %s/%s.git" % (clean_host(host), p) run_command(cmd) os.chdir(basedir) new_repos.append(p + '.git') @@ -293,9 +293,20 @@ def handle_updated_repos(conf, host, repos): def host_url_to_path(host): + "Convert host url from config to mirror dir path." + parts = host.rsplit("#", 1) + host = parts[0] host_p = urlparse.urlparse(host.rstrip("/")) path_adjusted = host_p.path.replace("/", "__") - return options.mirror_dir + "/" + host_p.netloc + path_adjusted + ret = options.mirror_dir + "/" + host_p.netloc + path_adjusted + if len(parts) > 1: + ret += "#" + parts[1] + return ret + + +def clean_host(host): + "Split any #N trailers from config host url." + return host.rsplit("#", 1)[0] def check_args(optparser, args, expected): diff --git a/mirror.conf.sample b/mirror.conf.sample index c40170d..be6a1b5 100644 --- a/mirror.conf.sample +++ b/mirror.conf.sample @@ -73,6 +73,11 @@ platform/hardware/ti/domx = platform/hardware/ti/domx-omapzoom [https://github.com] msg555/PowerTutor = platform/packages/apps/PowerTutor +# Sometimes you need to create different mirrors of the same server. +# Just append '#': +[https://github.com#2] +msg555/PowerTutor = platform2/packages/apps/PowerTutor + # [git://igloocommunity.org] # git/android/platform/vendor/st-ericsson/multimedia/linux/b2r2lib = platform/vendor/st-ericsson/multimedia/linux/b2r2lib -- cgit v1.2.3