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^'],
67 def cloneAllPackages(base):
68 for pkg in open('package-list'):
69 clonePackage(base, pkg.strip())
71 def mergeHistory(old_pkg, new_pkg, n):
74 subprocess.check_call(['git', 'push',
75 '../%s.git' % new_pkg,
76 'master:refs/heads/%s' % old_pkg],
77 cwd='%s.git' % old_pkg)
79 # Find the merge commit
81 p = subprocess.Popen(['git', 'rev-parse',
83 cwd='%s.git' % new_pkg,
84 stdout=subprocess.PIPE)
86 p = subprocess.Popen(['git', 'rev-list',
89 '--skip=%s' % (n - 1),
91 cwd='%s.git' % new_pkg,
92 stdout=subprocess.PIPE)
94 new_rev = p.stdout.read().split()[0].strip('-')
96 # Find any other parents of the merge commit
97 p = subprocess.Popen(['git', 'log',
101 cwd='%s.git' % new_pkg,
102 stdout=subprocess.PIPE)
104 parents = p.stdout.read().split()
106 # Find the additional parent we're adding
107 p = subprocess.Popen(['git', 'rev-parse',
109 cwd='%s.git' % new_pkg,
110 stdout=subprocess.PIPE)
112 parents.append(p.stdout.read().strip())
114 # Write out the grafts file
115 f = open('%s.git/info/grafts' % new_pkg, 'a')
116 print >>f, '%s %s' % (new_rev, ' '.join(parents))
120 subprocess.call(['git', 'filter-branch',
121 '--tag-name-filter', 'cat',
124 cwd='%s.git' % new_pkg)
126 subprocess.call(['git', 'branch',
129 cwd='%s.git' % new_pkg)
130 shutil.rmtree('%s.git/refs/original' % new_pkg, True)
132 def mergeHistories():
134 for line in open('merges'):
136 if line == '' or line[0] == '#':
139 merges.append(line.split())
145 shutil.rmtree('%s.git' % merge[0])
148 for pkg in glob.glob('*.git'):
149 subprocess.check_call(['git', 'tag', '-d', 'base'],
152 subprocess.check_call(['git', 'gc'],
155 if __name__ == '__main__':
159 base = 'svn://invirt.mit.edu/trunk'
161 cloneAllPackages(base)