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',
77 shutil.rmtree('%s.git/refs/original' % pkg, True)
81 def cloneAllPackages(base):
82 for pkg in open('package-list'):
83 clonePackage(base, pkg.strip())
85 def mergeHistory(old_pkg, new_pkg, n):
88 subprocess.check_call(['git', 'push',
89 '../%s.git' % new_pkg,
90 'master:refs/heads/%s' % old_pkg],
91 cwd='%s.git' % old_pkg)
93 # Find the merge commit
95 p = subprocess.Popen(['git', 'rev-parse',
97 cwd='%s.git' % new_pkg,
98 stdout=subprocess.PIPE)
100 p = subprocess.Popen(['git', 'rev-list',
103 '--skip=%s' % (n - 1),
105 cwd='%s.git' % new_pkg,
106 stdout=subprocess.PIPE)
108 new_rev = p.stdout.read().split()[0].strip('-')
110 # Find any other parents of the merge commit
111 p = subprocess.Popen(['git', 'log',
113 '--pretty=format:%P',
115 cwd='%s.git' % new_pkg,
116 stdout=subprocess.PIPE)
118 parents = p.stdout.read().split()
120 # Find the additional parent we're adding
121 p = subprocess.Popen(['git', 'rev-parse',
123 cwd='%s.git' % new_pkg,
124 stdout=subprocess.PIPE)
126 parents.append(p.stdout.read().strip())
128 # Write out the grafts file
129 f = open('%s.git/info/grafts' % new_pkg, 'a')
130 print >>f, '%s %s' % (new_rev, ' '.join(parents))
134 subprocess.call(['git', 'filter-branch',
135 '--tag-name-filter', 'cat',
138 cwd='%s.git' % new_pkg)
140 subprocess.call(['git', 'branch',
143 cwd='%s.git' % new_pkg)
144 shutil.rmtree('%s.git/refs/original' % new_pkg, True)
146 def mergeHistories():
148 for line in open('merges'):
150 if line == '' or line[0] == '#':
153 merges.append(line.split())
159 shutil.rmtree('%s.git' % merge[0])
162 for pkg in glob.glob('*.git'):
163 subprocess.check_call(['git', 'tag', '-d', 'base'],
166 subprocess.check_call(['git', 'gc'],
169 if __name__ == '__main__':
173 base = 'svn://invirt.mit.edu/trunk'
175 cloneAllPackages(base)