Use filter-branch to correct the trunk/packages/$package/$package
[invirt/scripts/git-migration.git] / git-migrate
index ccd9934..c5886a9 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import glob
 import os
 import sys
 import subprocess
@@ -29,6 +30,9 @@ def tagBase(pkg):
                           cwd='%s.git' % pkg)
 
 def clonePackage(base, pkg):
+    path = '%s/%s' % (base, pkg)
+    pkg = os.path.basename(pkg)
+    
     if not os.path.isdir('%s.git' % pkg):
         if os.path.isdir(pkg):
             shutil.rmtree(pkg)
@@ -39,7 +43,7 @@ def clonePackage(base, pkg):
                                '-Aauthors',
                                '-q',
                                '--no-metadata',
-                               '%s/packages/%s' % (base, pkg)],
+                               '%s' % path],
                               stdout=subprocess.PIPE)
         
         # Then make the repository bare, because git-svn can't do this
@@ -58,6 +62,18 @@ def clonePackage(base, pkg):
         subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
                               cwd='%s.git' % pkg)
     
+    # Early in the project's history, there were a bunch of double
+    # directory trees - i.e. the source was actually in
+    # trunk/packages/$package/$package. Correct for that
+    cwd = os.getcwd()
+    os.environ['PACKAGE'] = pkg
+    p = subprocess.check_call(['git', 'filter-branch',
+                               '--commit-filter', '%s "$@"' % os.path.join(cwd, 'filter-subdirs'),
+                               '--tag-name-filter', 'cat',
+                               '--',
+                               '--all'],
+                              cwd='%s.git' % pkg)
+    
     tagBase(pkg)
 
 def cloneAllPackages(base):
@@ -140,6 +156,14 @@ def mergeHistories():
     for merge in merges:
         shutil.rmtree('%s.git' % merge[0])
 
+def cleanupRepos():
+    for pkg in glob.glob('*.git'):
+        subprocess.check_call(['git', 'tag', '-d', 'base'],
+                              cwd='%s' % pkg)
+        
+        subprocess.check_call(['git', 'gc'],
+                              cwd='%s' % pkg)
+
 if __name__ == '__main__':
     try:
         base = sys.argv[1]
@@ -148,3 +172,4 @@ if __name__ == '__main__':
     
     cloneAllPackages(base)
     mergeHistories()
+    cleanupRepos()