[Pkg-ocaml-maint-commits] r5833 - /trunk/tools/svn2git/glondu_svn2git.py
glondu-guest at users.alioth.debian.org
glondu-guest at users.alioth.debian.org
Sun Jul 6 12:08:39 UTC 2008
Author: glondu-guest
Date: Sun Jul 6 12:08:38 2008
New Revision: 5833
URL: http://svn.debian.org/wsvn/?sc=1&rev=5833
Log:
More committers, more options for shell script generation
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=5833&op=diff
==============================================================================
--- trunk/tools/svn2git/glondu_svn2git.py (original)
+++ trunk/tools/svn2git/glondu_svn2git.py Sun Jul 6 12:08:38 2008
@@ -24,6 +24,9 @@
svnwdir_re = re.compile(r"^(/packages/ocaml/([0-9.beta]+|trunk)|/trunk/packages/ocaml/(trunk))(/.*|)$")
svnignore_re = re.compile(r"^/packages/ocaml(|/tags(/.*|))$")
+# For extracting tag names
+svntag_re = re.compile(r"^/(packages/ocaml/tags|tags/packages/ocaml)/([^/]+)")
+
# Mapping from alioth login to name and email (could be queried...)
users_dict = {
"glondu-guest": ("Stephane Glondu", "steph at glondu.net"),
@@ -31,15 +34,18 @@
"smimram-guest": ("Samuel Mimram", "samuel.mimram at ens-lyon.org"),
"zack": ("Stefano Zacchiroli", "zack at debian.org"),
"gareuselesinge": ("Enrico Tassi", "gareuselesinge at debian.org"),
+ "gares-guest": ("Enrico Tassi", "gareuselesinge at users.sourceforge.net"),
"treinen": ("Ralf Treinen", "treinen at debian.org"),
"gildor": ("Sylvain Le Gall", "gildor at debian.org"),
+ "gildor-guest": ("Sylvain Le Gall", "sylvain.le-gall at polytechnique.org"),
"toots": ("Romain Beauxis", "toots at debian.org"),
"jcristau": ("Julien Cristau", "jcristau at debian.org"),
"jcristau-guest": ("Julien Cristau", "julien.cristau at ens-lyon.org"),
"luther": ("Sven Luther", "luther at debian.org"),
"jerome": ("Jerome Marant", "jerome at debian.org"),
"ecc-guest": ("Eric Cooper", "ecc at cmu.edu"),
- "mfurr": ("Mike Furr", "mfurr at debian.org")
+ "mfurr": ("Mike Furr", "mfurr at debian.org"),
+ "berke-guest": ("Oguz Berke DURAK", "berke-dev at ouvaton.org"),
}
@@ -105,17 +111,19 @@
path_elts = logentry.getElementsByTagName("path")
self.files = [(x.getAttribute("action"), x.firstChild.nodeValue, get_copyfrom(x)) for x in path_elts]
+ def export_git_environment(self):
+ print "GIT_AUTHOR_NAME=" + escape_for_shell(self.name)
+ print "GIT_AUTHOR_EMAIL=" + escape_for_shell(self.email)
+ print "GIT_AUTHOR_DATE=" + escape_for_shell(self.date)
+ print "GIT_COMMITTER_NAME=" + escape_for_shell(self.name)
+ print "GIT_COMMITTER_EMAIL=" + escape_for_shell(self.email)
+ print "GIT_COMMITTER_DATE=" + escape_for_shell(self.date)
+
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)
-
+ self.export_git_environment()
working_dir = None
local_wdir = None
tgz = []
@@ -142,6 +150,7 @@
print "# cannot recognize working dir in (%s) %s" % (action, file)
if file.endswith(".tar.gz"):
print "# deal with (%s) %s manually" % (action, file)
+ nb_files -= 1
tgz.append(file)
if working_dir:
print "rsync -a --exclude=.svn --exclude='*.tar.gz' --delete ../svn/%s/debian ." % local_wdir
@@ -150,15 +159,25 @@
else:
print "# unable to guess working directory for revision %s" % self.rev
if nb_files:
- cmd = ""
+ cmd = "git commit -m " + escape_for_shell(self.msg)
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)
+ cmd = "# git commit -m " + escape_for_shell(self.msg).replace("\n", "\n# ")
print cmd.encode("utf-8")
print "popd\n"
+
+ def find_commit(self):
+ s, o = getstatusoutput("git log --date=iso | grep -B2 '%s'" % self.date)
+ nb_sha = 0
+ for line in o.split("\n"):
+ if line.startswith("commit "):
+ sha = line.split(" ")[1].strip()
+ print "%s %s" % (self.rev, sha)
+ nb_sha += 1
+ if nb_sha > 1:
+ print "# warning: %d commits found matching '%s'" % (nb_sha, self.date)
def setup_env(self):
os.putenv("GIT_AUTHOR_NAME", self.name)
@@ -250,6 +269,45 @@
class GitTag(GitCommit):
+
+ def export_sh(self):
+ print "echo Importing svn tag from revision %d into git" % self.rev
+ print "##( cd ../svn && svn update -r%d )" % self.rev
+ self.export_git_environment()
+ tag_name = None
+ parent_rev = None
+ for (action, file, copyfrom) in self.files:
+ if action == "A":
+ m = svntag_re.match(file)
+ if m:
+ tag_name = m.group(2)
+ if copyfrom:
+ rev = int(copyfrom.split("@")[1])
+ if parent_rev == None:
+ parent_rev = rev
+ elif parent_rev != rev:
+ print "# duplicate parent %s" % rev
+ else:
+ print "# unrecognized operation (%s) %s (will probably be skipped)" % (action, file)
+ if parent_rev:
+ commits = dico.get(parent_rev, [])
+ if len(commits) == 1:
+ print "git checkout %s" % commits[0]
+ else:
+ print "# %d commits, fill in manually (tag svn rev %d)" % (len(commits), parent_rev)
+ print "git checkout ????"
+ else:
+ print "# couldn't find the parent rev, fill in manually"
+ print "git checkout ????"
+ if tag_name:
+ cmd = "git tag debian/%s -m %s" % (tag_name, escape_for_shell(self.msg))
+ else:
+ print "# unable to find tag name"
+ for (action, file, copyfrom) in self.files:
+ print "# %s %s" % (action, file)
+ cmd = "# git tag ??? -m " + escape_for_shell(self.msg).replace("\n", "\n# ")
+ print cmd.encode("utf-8")
+ print
def commit(self):
m = svntag_re.match(self.msg)
@@ -305,24 +363,61 @@
if __name__ == "__main__":
- opts, args = getopt(sys.argv[1:], "p:t:r:x:")
+ opts, args = getopt(sys.argv[1:], "p:t:r:x:y:sde:")
package_name = None
tarball_location = "tarballs"
initial_revision = 0
xml = None
+ xml_tags = None
+ dict_mode = False
+ dico_file = 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
+ elif x == "-y": xml_tags = y
+ elif x == "-d": dict_mode = True
+ elif x == "-e": dico_file = y
+
+ if (xml or xml_tags) and not dict_mode:
+ print "#!/bin/zsh -e"
+ print "export GIT_AUTHOR_NAME"
+ print "export GIT_AUTHOR_EMAIL"
+ print "export GIT_AUTHOR_DATE"
+ print "export GIT_COMMITTER_NAME"
+ print "export GIT_COMMITTER_EMAIL"
+ print "export GIT_COMMITTER_DATE"
+ print
+
+ if dico_file:
+ global dico
+ dico = {}
+ for line in file(dico_file):
+ if not line.startswith("#"):
+ svn, git = line.strip().split(" ")
+ svn = int(svn)
+ dico.setdefault(svn, [])
+ dico[svn].append(git)
if xml:
xml = parse(xml)
logentries = xml.getElementsByTagName("logentry")
for x in logentries:
commit = GitCommit(x, None)
+ if dict_mode:
+ commit.find_commit()
+ else:
+ commit.export_sh()
+ sys.exit(0)
+
+ if xml_tags:
+ xml = parse(xml_tags)
+ logentries = xml.getElementsByTagName("logentry")
+ for x in logentries:
+ commit = GitTag(x, None)
commit.export_sh()
sys.exit(0)
@@ -338,7 +433,7 @@
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]
+ print >>sys.stderr, """Usages:
+ %(prog)s -p <package-name> [-t <tarball-location>] [-r <initial-revision>]
+ %(prog)s -x <xml-log>""" % { "prog": sys.argv[0] }
sys.exit(1)
More information about the Pkg-ocaml-maint-commits
mailing list