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, repo_path):
33 pkg = os.path.basename(repo_path)
35 if not os.path.isdir('%s.git' % pkg):
36 if os.path.isdir(pkg):
40 args.append('-Ttrunk/%s' % repo_path)
41 if repo_path.startswith('packages/'):
42 args.append('-tpackage_tags/%s' % pkg)
46 # Use --no-follow-parent because we're going to handle that with
48 subprocess.check_call(['git', 'svn', 'clone',
52 '--no-metadata'] + args,
53 stdout=subprocess.PIPE)
55 # Then make the repository bare, because git-svn can't do this
56 shutil.move('%s/.git' % pkg, '%s.git' % pkg)
58 subprocess.check_call(['git', 'config', 'core.bare', 'true'],
61 # Some of these repos have a rev where everything was deleted
62 # as a result of the move. We don't want that rev to exist.
63 p = subprocess.Popen(['git', 'ls-tree', 'HEAD'],
65 stdout=subprocess.PIPE)
67 if len(p.stdout.read()) == 0:
68 subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
71 # Early in the project's history, there were a bunch of double
72 # directory trees - i.e. the source was actually in
73 # trunk/packages/$package/$package. Correct for that
75 os.environ['PACKAGE'] = pkg
76 p = subprocess.check_call(['git', 'filter-branch',
77 '--commit-filter', '%s "$@"' % os.path.join(cwd, 'filter-subdirs'),
78 '--tag-name-filter', 'cat',
83 shutil.rmtree('%s.git/refs/original' % pkg, True)
87 def cloneAllPackages(base):
88 for pkg in open('package-list'):
89 clonePackage(base, pkg.strip())
91 def mergeHistory(old_pkg, new_pkg, n):
94 subprocess.check_call(['git', 'push',
95 '../%s.git' % new_pkg,
96 'master:refs/heads/%s' % old_pkg],
97 cwd='%s.git' % old_pkg)
99 # Find the merge commit
101 p = subprocess.Popen(['git', 'rev-parse',
103 cwd='%s.git' % new_pkg,
104 stdout=subprocess.PIPE)
106 p = subprocess.Popen(['git', 'rev-list',
109 '--skip=%s' % (n - 1),
111 cwd='%s.git' % new_pkg,
112 stdout=subprocess.PIPE)
114 new_rev = p.stdout.read().split()[0].strip('-')
116 # Find any other parents of the merge commit
117 p = subprocess.Popen(['git', 'log',
119 '--pretty=format:%P',
121 cwd='%s.git' % new_pkg,
122 stdout=subprocess.PIPE)
124 parents = p.stdout.read().split()
126 # Find the additional parent we're adding
127 p = subprocess.Popen(['git', 'rev-parse',
129 cwd='%s.git' % new_pkg,
130 stdout=subprocess.PIPE)
132 parents.append(p.stdout.read().strip())
134 # Write out the grafts file
135 f = open('%s.git/info/grafts' % new_pkg, 'a')
136 print >>f, '%s %s' % (new_rev, ' '.join(parents))
140 subprocess.call(['git', 'filter-branch',
141 '--tag-name-filter', 'cat',
144 cwd='%s.git' % new_pkg)
146 subprocess.call(['git', 'branch',
149 cwd='%s.git' % new_pkg)
150 shutil.rmtree('%s.git/refs/original' % new_pkg, True)
152 def mergeHistories():
154 for line in open('merges'):
156 if line == '' or line[0] == '#':
159 merges.append(line.split())
165 shutil.rmtree('%s.git' % merge[0])
168 for pkg in glob.glob('*.git'):
169 subprocess.check_call(['git', 'tag', '-d', 'base'],
172 subprocess.check_call(['git', 'gc'],
175 if __name__ == '__main__':
179 base = 'svn://invirt.mit.edu'
181 cloneAllPackages(base)