From 25ba7ed90abd8083fa3beab9ba0082b574ad72a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20M=2E=20Basto?= Date: Fri, 31 May 2019 19:52:33 +0100 Subject: [PATCH] Add argument --git-dir set a local dir without be compress/decompress --- svn2github.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/svn2github.py b/svn2github.py index 6be43c7..660993d 100755 --- a/svn2github.py +++ b/svn2github.py @@ -103,7 +103,7 @@ def save_cache(cache_path, tmp_path, git_dir): shutil.copyfile(tmp_path, cache_path) -def sync_github_mirror(github_repo, cache_dir, new_svn_url=None): +def sync_github_mirror(github_repo, cache_dir, new_svn_url=None, new_git_dir=None): if cache_dir: os.makedirs(cache_dir, exist_ok=True) cache_old_path = os.path.join(cache_dir, "cache." + github_repo.replace("/", ".") + ".tar") @@ -116,7 +116,12 @@ def sync_github_mirror(github_repo, cache_dir, new_svn_url=None): github_url = "git@github.com:" + github_repo + ".git" - with tempfile.TemporaryDirectory(prefix="svn2github-") as tmp_dir: + if not new_git_dir: + tmp_dir = os.path.join(tempfile.TemporaryDirectory(prefix="svn2github-"), "repo") + else: + tmp_dir = new_git_dir + + if tmp_dir: git_dir = os.path.join(tmp_dir, "repo") if cached and not new_svn_url: print("Using cached Git repository from " + cache_path) @@ -163,6 +168,7 @@ def sync_github_mirror(github_repo, cache_dir, new_svn_url=None): def main(): parser = argparse.ArgumentParser(description="Mirror SVN repositories to GitHub") parser.add_argument("--cache-dir", help="Directory to keep the cached data to avoid re-downloading all SVN and Git history each time. This is optional, but highly recommended") + parser.add_argument("--git-dir", help="git local dir without be compressed") subparsers = parser.add_subparsers() subparser_import = subparsers.add_parser("import", help="Import SVN repository to the GitHub repo") @@ -174,7 +180,8 @@ def main(): args = parser.parse_args(sys.argv[1:] or ["--help"]) new_svn_url = args.svn_url if "svn_url" in args else None - sync_github_mirror(args.github_repo, args.cache_dir, new_svn_url=new_svn_url) + new_git_dir = args.git_dir if "git_dir" in args else None + sync_github_mirror(args.github_repo, args.cache_dir, new_svn_url=new_svn_url, new_git_dir=new_git_dir)