1 | #!/usr/bin/python |
---|
2 | |
---|
3 | import os |
---|
4 | import sys |
---|
5 | import subprocess |
---|
6 | import shutil |
---|
7 | |
---|
8 | def clonePackage(base, pkg): |
---|
9 | if not os.path.isdir('%s.git' % pkg): |
---|
10 | if os.path.isdir(pkg): |
---|
11 | shutil.rmtree(pkg) |
---|
12 | # Use --no-follow-parent because we're going to handle that with |
---|
13 | # grafts. |
---|
14 | subprocess.check_call(['git', 'svn', 'clone', |
---|
15 | '--no-follow-parent', |
---|
16 | '-Aauthors', |
---|
17 | '-q', |
---|
18 | '--no-metadata', |
---|
19 | '%s/packages/%s' % (base, pkg)], |
---|
20 | stdout=subprocess.PIPE) |
---|
21 | |
---|
22 | # Then make the repository bare, because git-svn can't do this |
---|
23 | shutil.move('%s/.git' % pkg, '%s.git' % pkg) |
---|
24 | shutil.rmtree(pkg) |
---|
25 | subprocess.check_call(['git', 'config', 'core.bare', 'true'], |
---|
26 | cwd='%s.git' % pkg) |
---|
27 | |
---|
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'], |
---|
31 | cwd='%s.git' % pkg, |
---|
32 | stdout=subprocess.PIPE) |
---|
33 | p.wait() |
---|
34 | if len(p.stdout.read()) == 0: |
---|
35 | subprocess.check_call(['git', 'reset', 'HEAD^'], |
---|
36 | cwd='%s.git' % pkg) |
---|
37 | |
---|
38 | def cloneAllPackages(base): |
---|
39 | for pkg in open('package-list'): |
---|
40 | clonePackage(base, pkg.strip()) |
---|
41 | |
---|
42 | def mergeHistory(old_pkg, new_pkg, n): |
---|
43 | cwd = os.getcwd() |
---|
44 | subprocess.check_call(['git', 'push', |
---|
45 | 'file:///%s/%s.git' % (cwd, new_pkg), |
---|
46 | 'master:refs/heads/%s' % old_pkg], |
---|
47 | cwd=new_pkg) |
---|
48 | |
---|
49 | def mergeHistories(): |
---|
50 | for line in open('grafts'): |
---|
51 | line = line.strip() |
---|
52 | if line[0] == '#' or line == '': |
---|
53 | continue |
---|
54 | |
---|
55 | old_pkg, new_pkg, n = line.split() |
---|
56 | mergeHistory(old_pkg, new_pkg, int(n)) |
---|
57 | |
---|
58 | if __name__ == '__main__': |
---|
59 | try: |
---|
60 | base = sys.argv[1] |
---|
61 | except: |
---|
62 | base = 'svn://invirt.mit.edu/trunk' |
---|
63 | |
---|
64 | cloneAllPackages(base) |
---|
65 | mergeHistories() |
---|