[Pkg-ocaml-maint-commits] r5617 - /trunk/tools/svn2git/glondu_svn2git.py
glondu-guest at users.alioth.debian.org
glondu-guest at users.alioth.debian.org
Sat May 10 11:16:32 UTC 2008
Author: glondu-guest
Date: Sat May 10 11:16:31 2008
New Revision: 5617
URL: http://svn.debian.org/wsvn/?sc=1&rev=5617
Log:
Handle deletions and set git-commit environment at the right moment.
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=5617&op=diff
==============================================================================
--- trunk/tools/svn2git/glondu_svn2git.py (original)
+++ trunk/tools/svn2git/glondu_svn2git.py Sat May 10 11:16:31 2008
@@ -16,6 +16,7 @@
from xml.dom.minidom import parseString
+# For extracting tgz names from svn-log output
svntag_re = re.compile(r"^\[svn-buildpackage\][^(]+\(([^)]+)\)$")
@@ -100,18 +101,16 @@
def commit(self):
tarball_path = "../svn/" + self.svn2git.tarball_path
os.chdir("git")
+ self.setup_env()
# Call git-import-orig if needed
if os.path.exists(tarball_path):
- n = []
- for x in os.listdir(tarball_path):
- if not self.svn2git.seen.has_key(x):
- n.append(x)
+ n = set(os.listdir(tarball_path)) - self.svn2git.seen
if len(n) == 1:
- tgz = n[0]
+ tgz = n.pop()
print "New upstream tarball:", tgz
run_command("git-import-orig", "git-import-orig --pristine-tar --no-dch %s/%s" % (tarball_path, tgz))
- self.svn2git.seen[n[0]] = True
+ self.svn2git.seen.add(tgz)
elif len(n) > 1:
print "Too many new tarballs:", ", ".join(n)
sys.exit(1)
@@ -119,21 +118,34 @@
print "No upstream directory!"
print "Committing revision %d to git..." % self.rev,
- self.setup_env()
-
- s, o = getstatusoutput("rsync -rt --exclude=.svn ../svn/trunk/debian/ debian")
+
+ # Copying files from svn
+ s, o = getstatusoutput("rsync -a --exclude=.svn --delete ../svn/trunk/debian/ debian")
if s:
print "nothing to sync! (rsync returned with code %d)" % s
os.chdir("..")
return None
+
+ # Adding modifications
s, o = getstatusoutput("git add .")
if s:
print "nothing to add! (git returned with code %d)" % s
os.chdir("..")
return None
+
+ # Deleting files
+ old = set(x for x in run_command("git-ls-files", "git ls-files -z debian").split("\0") if x)
+ new = set(x for x in run_command("find", "find debian -not -type d -print0").split("\0") if x)
+ deleted = old-new
+ if len(deleted) > 0:
+ run_command("git-rm", "git rm %s" % " ".join(deleted))
+
+ # Writing log
f = NamedTemporaryFile()
f.file.write(self.msg.encode("UTF-8"))
f.file.close()
+
+ # Actually commit
s, o = getstatusoutput("git commit -F%s" % f.name)
f.close()
if s:
@@ -176,6 +188,7 @@
class Svn2Git:
def __init__(self, package, tarball_path):
+ # Svn repos-specific paths
self.tarball_path = tarball_path
self.repos = "svn://svn.debian.org/svn/pkg-ocaml-maint/trunk/packages/%s" % package
self.tagrepos = "svn://svn.debian.org/svn/pkg-ocaml-maint/tags/packages/%s" % package
@@ -183,18 +196,17 @@
r = run_command("svn", "svn log --xml %s" % self.repos)
r = parseString(r).getElementsByTagName("logentry")
revs = [GitCommit(x, self) for x in r]
+ # Retrieve tags
r = run_command("svn", "svn log --xml %s" % self.tagrepos)
r = parseString(r).getElementsByTagName("logentry")
tags = [GitTag(x, self) for x in r]
+ # Merge and sort tags
self.logentries = revs+tags
self.logentries.sort(key=lambda x: x.rev)
# Initialize the list of already-seen tarballs
- self.seen = {".svn": True}
s, o = getstatusoutput("cd git && git log -b pristine-tar 2>/dev/null|sed -nr 's/^ pristine-tar data for //p'")
- for x in o.split("\n"):
- if x:
- print "Seen:", x
- self.seen[x] = True
+ self.seen = set(x for x in o.split("\n") if x)
+ self.seen.add(".svn")
def do(self, from_revision):
for x in self.logentries:
@@ -205,7 +217,7 @@
if __name__ == "__main__":
- #run_command("clean", "rm -Rf git svn")
- #git_init()
+ run_command("clean", "rm -Rf git svn")
+ git_init()
a = Svn2Git("ocsigen", "upstream")
a.do(0)
More information about the Pkg-ocaml-maint-commits
mailing list