[Pkg-ocaml-maint-commits] r5816 - /trunk/tools/svn2git/glondu_svn2git.py
glondu-guest at users.alioth.debian.org
glondu-guest at users.alioth.debian.org
Sun Jun 29 22:29:56 UTC 2008
Author: glondu-guest
Date: Sun Jun 29 22:29:56 2008
New Revision: 5816
URL: http://svn.debian.org/wsvn/?sc=1&rev=5816
Log:
Add command line options and possibility to export a shell script
This is still ongoing work...
Modified:
trunk/tools/svn2git/glondu_svn2git.py
Modified: trunk/tools/svn2git/glondu_svn2git.py
URL: http://svn.debian.org/wsvn/trunk/tools/svn2git/glondu_svn2git.py?rev=5816&op=diff
==============================================================================
--- trunk/tools/svn2git/glondu_svn2git.py (original)
+++ trunk/tools/svn2git/glondu_svn2git.py Sun Jun 29 22:29:56 2008
@@ -13,12 +13,16 @@
from debian_bundle.debian_support import version_compare
from tempfile import NamedTemporaryFile
from commands import getoutput, getstatusoutput
-from xml.dom.minidom import parseString
+from xml.dom.minidom import parseString, parse
+from getopt import getopt
# For extracting tgz names from svn-log output
svntag_re = re.compile(r"^\[svn-buildpackage\][^(]+\(([^)]+)\)$")
+# For extracting working dir from svn-log output
+svnwdir_re = re.compile(r"^(/packages/ocaml/([0-9.beta]+|trunk)|/trunk/packages/ocaml/(trunk))(/.*|)$")
+svnignore_re = re.compile(r"^/packages/ocaml(|/tags(/.*|))$")
# Mapping from alioth login to name and email (could be queried...)
users_dict = {
@@ -70,9 +74,20 @@
raise ValueError("Unable to parse date '%s'" % str)
+def escape_for_shell(str):
+ return "'" + str.replace("'", "'\\''") + "'"
+
+
def git_init():
os.mkdir("git")
run_command("git", "cd git && git init")
+
+
+def get_copyfrom(path):
+ if path.hasAttribute("copyfrom-path"):
+ return "%s@%s" % (path.getAttribute("copyfrom-path"), path.getAttribute("copyfrom-rev"))
+ else:
+ return None
class GitCommit:
@@ -81,12 +96,69 @@
self.svn2git = svn2git
self.rev = int(logentry.getAttribute("revision"))
msg_elt = logentry.getElementsByTagName("msg")[0].firstChild
- self.msg = msg_elt and msg_elt.nodeValue or "No log message"
+ self.msg = msg_elt and msg_elt.nodeValue.rstrip() or "No log message"
user_elt = logentry.getElementsByTagName("author")[0]
self.name, self.email = users_dict[user_elt.firstChild.nodeValue]
date_elt = logentry.getElementsByTagName("date")[0]
date = parse_datetime(date_elt.firstChild.nodeValue)
self.date = date.strftime("%Y-%m-%d %H:%M:%S %z")
+ path_elts = logentry.getElementsByTagName("path")
+ self.files = [(x.getAttribute("action"), x.firstChild.nodeValue, get_copyfrom(x)) for x in path_elts]
+
+ def export_sh(self):
+ print "echo Importing svn revision %d into git" % self.rev
+ print "( cd svn && svn update -r%d )" % self.rev
+ print "pushd git"
+ print "export GIT_AUTHOR_NAME=" + escape_for_shell(self.name)
+ print "export GIT_AUTHOR_EMAIL=" + escape_for_shell(self.email)
+ print "export GIT_AUTHOR_DATE=" + escape_for_shell(self.date)
+ print "export GIT_COMMITTER_NAME=" + escape_for_shell(self.name)
+ print "export GIT_COMMITTER_EMAIL=" + escape_for_shell(self.email)
+ print "export GIT_COMMITTER_DATE=" + escape_for_shell(self.date)
+
+ working_dir = None
+ local_wdir = None
+ tgz = []
+ nb_files = 0
+ for (action, file, copyfrom) in self.files:
+ if svnignore_re.match(file):
+ print "# ignored (%s) %s" % (action, file)
+ continue
+ if copyfrom:
+ print "# copyfrom %s to (%s) %s" % (copyfrom, action, file)
+ if action in ("M", "A", "R"):
+ if working_dir:
+ if (file+"/").startswith(working_dir):
+ nb_files += 1
+ else:
+ print "# unrecognized file (%s) %s (will probably be skipped)" % (action, file)
+ else:
+ m = svnwdir_re.match(file)
+ if m:
+ working_dir = m.group(1) + "/"
+ local_wdir = m.group(2) or m.group(3)
+ nb_files += 1
+ else:
+ print "# cannot recognize working dir in (%s) %s" % (action, file)
+ if file.endswith(".tar.gz"):
+ print "# deal with (%s) %s manually" % (action, file)
+ tgz.append(file)
+ if working_dir:
+ print "rsync -a --exclude=.svn --exclude='*.tar.gz' --delete ../svn/%s/debian ." % local_wdir
+ print "git add ."
+ print "git add -u"
+ else:
+ print "# unable to guess working directory for revision %s" % self.rev
+ if nb_files:
+ cmd = ""
+ else:
+ print "# nothing to commit"
+ for (action, file, x) in self.files:
+ print "# %s %s" % (action, file)
+ cmd = "# "
+ cmd += "git commit -m " + escape_for_shell(self.msg)
+ print cmd.encode("utf-8")
+ print "popd\n"
def setup_env(self):
os.putenv("GIT_AUTHOR_NAME", self.name)
@@ -233,20 +305,40 @@
if __name__ == "__main__":
- if len(sys.argv) < 4:
- print "Usage: %s <package-name> <tarball-location> <initial-revision>" % sys.argv[0]
- sys.exit(1)
-
- package_name = sys.argv[1]
- tarball_location = sys.argv[2]
- initial_revision = int(sys.argv[3])
-
- if initial_revision == 0:
- run_command("clean", "rm -Rf git svn")
- git_init()
-
- print "Retrieving logs...",
- a = Svn2Git(package_name, tarball_location)
- print "OK!"
- print "Here we go!"
- a.do(initial_revision)
+ opts, args = getopt(sys.argv[1:], "p:t:r:x:")
+
+ package_name = None
+ tarball_location = "tarballs"
+ initial_revision = 0
+ xml = None
+
+ for (x, y) in opts:
+ if x == "-p": package_name = y
+ elif x == "-t": tarball_location = y
+ elif x == "-r": initial_revision = y
+ elif x == "-x": xml = y
+
+ if xml:
+ xml = parse(xml)
+ logentries = xml.getElementsByTagName("logentry")
+ for x in logentries:
+ commit = GitCommit(x, None)
+ commit.export_sh()
+ sys.exit(0)
+
+ if package_name:
+ if initial_revision == 0:
+ run_command("clean", "rm -Rf git svn")
+ git_init()
+
+ print "Retrieving logs...",
+ a = Svn2Git(package_name, tarball_location)
+ print "OK!"
+ print "Here we go!"
+ a.do(initial_revision)
+ sys.exit(0)
+
+ print >>sys.stderr, "Usages:"
+ print >>sys.stderr, " %s -p <package-name> [-t <tarball-location>] [-r <initial-revision>]" % sys.argv[0]
+ print >>sys.stderr, " %s -x <xml-log>" % sys.argv[0]
+ sys.exit(1)
More information about the Pkg-ocaml-maint-commits
mailing list