10 p = subprocess.Popen(['git', 'tag',
14 stdout=subprocess.PIPE)
16 if p.stdout.read().strip() != '':
19 p = subprocess.Popen(['git', 'rev-list',
23 stdout=subprocess.PIPE)
25 base = p.stdout.read().split()[0]
27 subprocess.check_call(['git', 'tag',
32 def clonePackage(base, pkg):
33 path = '%s/%s' % (base, pkg)
34 pkg = os.path.basename(pkg)
36 if not os.path.isdir('%s.git' % pkg):
37 if os.path.isdir(pkg):
39 # Use --no-follow-parent because we're going to handle that with
41 subprocess.check_call(['git', 'svn', 'clone',
47 stdout=subprocess.PIPE)
49 # Then make the repository bare, because git-svn can't do this
50 shutil.move('%s/.git' % pkg, '%s.git' % pkg)
52 subprocess.check_call(['git', 'config', 'core.bare', 'true'],
55 # Some of these repos have a rev where everything was deleted
56 # as a result of the move. We don't want that rev to exist.
57 p = subprocess.Popen(['git', 'ls-tree', 'HEAD'],
59 stdout=subprocess.PIPE)
61 if len(p.stdout.read()) == 0:
62 subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
65 # Early in the project's history, there were a bunch of double
66 # directory trees - i.e. the source was actually in
67 # trunk/packages/$package/$package. Correct for that
69 os.environ['PACKAGE'] = pkg
70 p = subprocess.check_call(['git', 'filter-branch',
71 '--commit-filter', '%s "$@"' % os.path.join(cwd, 'filter-subdirs'),
72 '--tag-name-filter', 'cat',
79 def cloneAllPackages(base):
80 for pkg in open('package-list'):
81 clonePackage(base, pkg.strip())
83 def mergeHistory(old_pkg, new_pkg, n):
86 subprocess.check_call(['git', 'push',
87 '../%s.git' % new_pkg,
88 'master:refs/heads/%s' % old_pkg],
89 cwd='%s.git' % old_pkg)
91 # Find the merge commit
93 p = subprocess.Popen(['git', 'rev-parse',
95 cwd='%s.git' % new_pkg,
96 stdout=subprocess.PIPE)
98 p = subprocess.Popen(['git', 'rev-list',
101 '--skip=%s' % (n - 1),
103 cwd='%s.git' % new_pkg,
104 stdout=subprocess.PIPE)
106 new_rev = p.stdout.read().split()[0].strip('-')
108 # Find any other parents of the merge commit
109 p = subprocess.Popen(['git', 'log',
111 '--pretty=format:%P',
113 cwd='%s.git' % new_pkg,
114 stdout=subprocess.PIPE)
116 parents = p.stdout.read().split()
118 # Find the additional parent we're adding
119 p = subprocess.Popen(['git', 'rev-parse',
121 cwd='%s.git' % new_pkg,
122 stdout=subprocess.PIPE)
124 parents.append(p.stdout.read().strip())
126 # Write out the grafts file
127 f = open('%s.git/info/grafts' % new_pkg, 'a')
128 print >>f, '%s %s' % (new_rev, ' '.join(parents))
132 subprocess.call(['git', 'filter-branch',
133 '--tag-name-filter', 'cat',
136 cwd='%s.git' % new_pkg)
138 subprocess.call(['git', 'branch',
141 cwd='%s.git' % new_pkg)
142 shutil.rmtree('%s.git/refs/original' % new_pkg, True)
144 def mergeHistories():
146 for line in open('merges'):
148 if line == '' or line[0] == '#':
151 merges.append(line.split())
157 shutil.rmtree('%s.git' % merge[0])
160 for pkg in glob.glob('*.git'):
161 subprocess.check_call(['git', 'tag', '-d', 'base'],
164 subprocess.check_call(['git', 'gc'],
167 if __name__ == '__main__':
171 base = 'svn://invirt.mit.edu/trunk'
173 cloneAllPackages(base)