Skip to content

Commit

Permalink
Add argument --git-dir set a local dir without be compress/decompress
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomb2 committed May 31, 2019
1 parent 024d24d commit 25ba7ed
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions svn2github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -116,7 +116,12 @@ def sync_github_mirror(github_repo, cache_dir, new_svn_url=None):

github_url = "[email protected]:" + 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)
Expand Down Expand Up @@ -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")
Expand All @@ -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)



Expand Down

0 comments on commit 25ba7ed

Please sign in to comment.