8 def clonePackage(base, pkg):
9 if not os.path.isdir('%s.git' % pkg):
10 if os.path.isdir(pkg):
12 # Use --no-follow-parent because we're going to handle that with
14 subprocess.check_call(['git', 'svn', 'clone',
19 '%s/packages/%s' % (base, pkg)],
20 stdout=subprocess.PIPE)
22 # Then make the repository bare, because git-svn can't do this
23 shutil.move('%s/.git' % pkg, '%s.git' % pkg)
25 subprocess.check_call(['git', 'config', 'core.bare', 'true'],
28 # Some of these repos have a rev where everything was deleted
29 # as a result of the move. We don't want that rev to exist.
30 p = subprocess.Popen(['git', 'ls-files'],
32 stdout=subprocess.PIPE)
34 if len(p.stdout.read()) == 0:
35 subprocess.check_call(['git', 'reset', 'HEAD^'],
38 def cloneAllPackages(base):
39 for pkg in open('package-list'):
40 clonePackage(base, pkg.strip())
42 def mergeHistory(old_pkg, new_pkg, n):
44 subprocess.check_call(['git', 'push',
45 'file:///%s/%s.git' % (cwd, new_pkg),
46 'master:refs/heads/%s' % old_pkg],
47 cwd='%s.git' % new_pkg)
50 p = subprocess.Popen(['git', 'rev-list',
54 cwd='%s.git' % new_pkg,
55 stdout=subprocess.PIPE)
57 new_rev = p.stdout.read().split()[0]
60 # If n isn't 0, then n has a parent commit already that we
61 # shouldn't forget about.
63 p = subprocess.Popen(['git', 'rev-parse',
65 cwd='%s.git' % new_pkg,
66 stdout=subprocess.PIPE)
68 graft.append(p.stdout.read().strip())
70 # And regardless, the HEAD of old_pkg should be a parent of
72 p = subprocess.Popen(['git', 'rev-parse',
74 cwd='%s.git' % old_pkg,
75 stdout=subprocess.PIPE)
77 graft.append(p.stdout.read().strip())
79 f = open('%s.git/info/grafts' % new_pkg, 'a')
81 print >>f, ' '.join(graft)
85 for line in open('grafts'):
87 if line[0] == '#' or line == '':
90 grafts.append(line.split())
95 for line in open('package-list'):
97 subprocess.check_call(['git', 'filter-branch',
103 shutil.rmtree('%s.git' % graft[0])
105 if __name__ == '__main__':
109 base = 'svn://invirt.mit.edu/trunk'
111 cloneAllPackages(base)