Created
October 27, 2017 15:58
-
-
Save aravindgv/1a27df3c4fab0fb1294e204e3e503e0a to your computer and use it in GitHub Desktop.
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
import argparse | |
from subprocess import check_output,PIPE,run | |
import re | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-u","--svn-url",dest="svn_url",help="Subversion URL") | |
parser.add_argument("-n","--last-rev",dest="rev",help="Clone last N num revision",type=int) | |
parser.add_argument("-d","--output-dir",dest="mydir",help="Clone to this directory") | |
args = parser.parse_args() | |
print("SvnUrl {} nRevsions {} CloneDirectory {} ".format(args.svn_url,args.rev,args.mydir)) | |
get_rev = "--limit=" + str(args.rev) | |
svnurl = args.svn_url | |
REV_COMMAND = ['svn','log', args.svn_url,'-rHEAD:1', get_rev] | |
def getsvnrev(rev): | |
log = run(rev,stdout=PIPE,universal_newlines=True).stdout | |
#log = check_output(rev,universal_newlines=True) | |
print(log) | |
res = re.findall(r'^r[0-9][0-9][0-9][0-9]+', log, flags=re.MULTILINE)[-1][1:] | |
return res | |
svnrev = getsvnrev(REV_COMMAND) | |
lastrev = "-r" + svnrev + ":HEAD" | |
SVN_GIT_COMMAND = ['git','svn','clone',lastrev,args.svn_url,args.mydir] | |
def gitsvnclone(svn2git_cmd): | |
print("Migrating SVN Repo from revision :",svnrev) | |
clone = check_output(svn2git_cmd).decode('utf-8') | |
return clone | |
git2svn = gitsvnclone(SVN_GIT_COMMAND) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Find an SVN revision that occurred N revisions ago and Perform a git svn clone based on the last N revisions of the SVN repo. This is useful if you have a giant SVN repo you want to move to git, but you don't want to clone the entire history.