-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add argument --git-dir set a local dir without be compress/decompress
- Loading branch information
Showing
1 changed file
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = "[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) | ||
|
@@ -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) | ||
|
||
|
||
|
||
|