9 p = subprocess.Popen(['git', 'tag',
13 stdout=subprocess.PIPE)
15 if p.stdout.read().strip() != '':
18 p = subprocess.Popen(['git', 'rev-list',
22 stdout=subprocess.PIPE)
24 base = p.stdout.read().split()[0]
26 subprocess.check_call(['git', 'tag',
31 def clonePackage(base, pkg):
32 if not os.path.isdir('%s.git' % pkg):
33 if os.path.isdir(pkg):
35 # Use --no-follow-parent because we're going to handle that with
37 subprocess.check_call(['git', 'svn', 'clone',
42 '%s/packages/%s' % (base, pkg)],
43 stdout=subprocess.PIPE)
45 # Then make the repository bare, because git-svn can't do this
46 shutil.move('%s/.git' % pkg, '%s.git' % pkg)
48 subprocess.check_call(['git', 'config', 'core.bare', 'true'],
51 # Some of these repos have a rev where everything was deleted
52 # as a result of the move. We don't want that rev to exist.
53 p = subprocess.Popen(['git', 'ls-tree', 'HEAD'],
55 stdout=subprocess.PIPE)
57 if len(p.stdout.read()) == 0:
58 subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
63 def cloneAllPackages(base):
64 for pkg in open('package-list'):
65 clonePackage(base, pkg.strip())
67 def mergeHistory(old_pkg, new_pkg, n):
70 subprocess.check_call(['git', 'push',
71 '../%s.git' % new_pkg,
72 'master:refs/heads/%s' % old_pkg],
73 cwd='%s.git' % old_pkg)
75 # Find the merge commit
77 p = subprocess.Popen(['git', 'rev-parse',
79 cwd='%s.git' % new_pkg,
80 stdout=subprocess.PIPE)
82 p = subprocess.Popen(['git', 'rev-list',
85 '--skip=%s' % (n - 1),
87 cwd='%s.git' % new_pkg,
88 stdout=subprocess.PIPE)
90 new_rev = p.stdout.read().split()[0].strip('-')
92 # Find any other parents of the merge commit
93 p = subprocess.Popen(['git', 'log',
97 cwd='%s.git' % new_pkg,
98 stdout=subprocess.PIPE)
100 parents = p.stdout.read().split()
102 # Find the additional parent we're adding
103 p = subprocess.Popen(['git', 'rev-parse',
105 cwd='%s.git' % new_pkg,
106 stdout=subprocess.PIPE)
108 parents.append(p.stdout.read().strip())
110 # Write out the grafts file
111 f = open('%s.git/info/grafts' % new_pkg, 'a')
112 print >>f, '%s %s' % (new_rev, ' '.join(parents))
116 subprocess.call(['git', 'filter-branch',
117 '--tag-name-filter', 'cat',
120 cwd='%s.git' % new_pkg)
122 subprocess.call(['git', 'branch',
125 cwd='%s.git' % new_pkg)
126 shutil.rmtree('%s.git/refs/original' % new_pkg, True)
128 def mergeHistories():
130 for line in open('merges'):
132 if line == '' or line[0] == '#':
135 merges.append(line.split())
141 shutil.rmtree('%s.git' % merge[0])
143 if __name__ == '__main__':
147 base = 'svn://invirt.mit.edu/trunk'
149 cloneAllPackages(base)