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 path = '%s/%s' % (base, pkg)
33 pkg = os.path.basename(pkg)
35 if not os.path.isdir('%s.git' % pkg):
36 if os.path.isdir(pkg):
38 # Use --no-follow-parent because we're going to handle that with
40 subprocess.check_call(['git', 'svn', 'clone',
46 stdout=subprocess.PIPE)
48 # Then make the repository bare, because git-svn can't do this
49 shutil.move('%s/.git' % pkg, '%s.git' % pkg)
51 subprocess.check_call(['git', 'config', 'core.bare', 'true'],
54 # Some of these repos have a rev where everything was deleted
55 # as a result of the move. We don't want that rev to exist.
56 p = subprocess.Popen(['git', 'ls-tree', 'HEAD'],
58 stdout=subprocess.PIPE)
60 if len(p.stdout.read()) == 0:
61 subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
66 def cloneAllPackages(base):
67 for pkg in open('package-list'):
68 clonePackage(base, pkg.strip())
70 def mergeHistory(old_pkg, new_pkg, n):
73 subprocess.check_call(['git', 'push',
74 '../%s.git' % new_pkg,
75 'master:refs/heads/%s' % old_pkg],
76 cwd='%s.git' % old_pkg)
78 # Find the merge commit
80 p = subprocess.Popen(['git', 'rev-parse',
82 cwd='%s.git' % new_pkg,
83 stdout=subprocess.PIPE)
85 p = subprocess.Popen(['git', 'rev-list',
88 '--skip=%s' % (n - 1),
90 cwd='%s.git' % new_pkg,
91 stdout=subprocess.PIPE)
93 new_rev = p.stdout.read().split()[0].strip('-')
95 # Find any other parents of the merge commit
96 p = subprocess.Popen(['git', 'log',
100 cwd='%s.git' % new_pkg,
101 stdout=subprocess.PIPE)
103 parents = p.stdout.read().split()
105 # Find the additional parent we're adding
106 p = subprocess.Popen(['git', 'rev-parse',
108 cwd='%s.git' % new_pkg,
109 stdout=subprocess.PIPE)
111 parents.append(p.stdout.read().strip())
113 # Write out the grafts file
114 f = open('%s.git/info/grafts' % new_pkg, 'a')
115 print >>f, '%s %s' % (new_rev, ' '.join(parents))
119 subprocess.call(['git', 'filter-branch',
120 '--tag-name-filter', 'cat',
123 cwd='%s.git' % new_pkg)
125 subprocess.call(['git', 'branch',
128 cwd='%s.git' % new_pkg)
129 shutil.rmtree('%s.git/refs/original' % new_pkg, True)
131 def mergeHistories():
133 for line in open('merges'):
135 if line == '' or line[0] == '#':
138 merges.append(line.split())
144 shutil.rmtree('%s.git' % merge[0])
146 if __name__ == '__main__':
150 base = 'svn://invirt.mit.edu/trunk'
152 cloneAllPackages(base)