diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-09-29 14:43:34 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-09-29 14:43:34 +0300 |
commit | df943095dc186eda4dd776bc2657b0c89c49a660 (patch) | |
tree | 063de0aede6ec308d650cda7124aa1895b02fb30 | |
parent | d07b2ebef6994784aa032e67c8e341a50d8d3d27 (diff) |
Elaborate handling of tree URLs with paths.
Paths in URLs are now allowed, and will be encoded in top-level mirror dir
name (with slashes replaced by double-underscores).
Change-Id: Ia63bf33f0ebd102932ce0ecb3c4075f27f8c1b98
-rwxr-xr-x | git-gerrit-mirror | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/git-gerrit-mirror b/git-gerrit-mirror index 7cf0f7d..832ad38 100755 --- a/git-gerrit-mirror +++ b/git-gerrit-mirror @@ -51,7 +51,6 @@ class MirrorConfig(object): host = l[1:-1] if not host.startswith(DEST_KEYWORD): assert "://" in host, "URL schema is required in " + l - assert "/" not in host.split("://")[1], "Only hostname (no path) allowed in " + l host_proj_map = {} host_wildcard_map = {} host_vars = {} @@ -248,6 +247,10 @@ def push_repos(host, git_repos, force=False): cmdline = "time git push%s %s/%s.git 'refs/heads/*' 'refs/tags/*'" % (force_opt, repo_root, mirror_projname) run_command(cmdline) +def host_url_to_path(host): + host_p = urlparse.urlparse(host.rstrip("/")) + return options.mirror_dir + "/" + host_p.netloc + host_p.path.replace("/", "__") + def check_args(optparser, args, expected): if len(args) != expected: optparser.error("Wrong number of arguments") @@ -323,14 +326,14 @@ elif args[0] == "clone": log.debug("=== Processing: %s ===", host) projects = get_project_map_for_a_host(host).keys() host_p = urlparse.urlparse(host) - clone_repos(host, options.mirror_dir + "/" + host_p.netloc + host_p.path, projects) + clone_repos(host, host_url_to_path(host), projects) elif args[0] == "fetch": check_args(optparser, args, 1) if not options.mirror_dir: optparser.error("--mirror-dir is required") for host in conf.get_hosts(options.upstream): host_p = urlparse.urlparse(host) - git_repos = scan_git_projects(options.mirror_dir + "/" + host_p.netloc) + git_repos = scan_git_projects(host_url_to_path(host)) log.info("=== Processing: %s (%d repositories) ===", host, len(git_repos)) fetch_repos(git_repos) elif args[0] == "push": @@ -339,7 +342,7 @@ elif args[0] == "push": optparser.error("--mirror-dir is required") for host in conf.get_hosts(options.upstream): host_p = urlparse.urlparse(host) - git_repos = scan_git_projects(options.mirror_dir + "/" + host_p.netloc) + git_repos = scan_git_projects(host_url_to_path(host)) log.info("=== Processing: %s (%d repositories) ===", host, len(git_repos)) push_repos(host, git_repos, force=options.force) elif args[0] in ("upstream-ls", "ls-upstream"): |