source: trunk/scripts/git-migration/git-migrate @ 1892

Last change on this file since 1892 was 1892, checked in by broder, 16 years ago

Simplify out the need to know the CWD.

  • Property svn:executable set to *
File size: 2.1 KB
RevLine 
[1866]1#!/usr/bin/python
2
[1874]3import os
[1866]4import sys
5import subprocess
[1869]6import shutil
[1866]7
8def clonePackage(base, pkg):
[1874]9    if not os.path.isdir('%s.git' % pkg):
10        if os.path.isdir(pkg):
11            shutil.rmtree(pkg)
12        # Use --no-follow-parent because we're going to handle that with
13        # grafts.
[1875]14        subprocess.check_call(['git', 'svn', 'clone',
15                               '--no-follow-parent',
[1874]16                               '-Aauthors',
17                               '-q',
[1875]18                               '--no-metadata',
19                               '%s/packages/%s' % (base, pkg)],
[1874]20                              stdout=subprocess.PIPE)
21       
22        # Then make the repository bare, because git-svn can't do this
23        shutil.move('%s/.git' % pkg, '%s.git' % pkg)
[1875]24        shutil.rmtree(pkg)
25        subprocess.check_call(['git', 'config', 'core.bare', 'true'],
26                              cwd='%s.git' % pkg)
[1876]27       
28    # Some of these repos have a rev where everything was deleted
29    # as a result of the move. We don't want that rev to exist.
[1891]30    p = subprocess.Popen(['git', 'ls-tree', 'HEAD'],
[1876]31                         cwd='%s.git' % pkg,
32                         stdout=subprocess.PIPE)
33    p.wait()
34    if len(p.stdout.read()) == 0:
[1888]35        subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
[1876]36                              cwd='%s.git' % pkg)
[1866]37
38def cloneAllPackages(base):
39    for pkg in open('package-list'):
40        clonePackage(base, pkg.strip())
41
[1880]42def mergeHistory(old_pkg, new_pkg, n):
[1881]43    subprocess.check_call(['git', 'push',
[1892]44                           '../%s.git' % new_pkg,
[1881]45                           'master:refs/heads/%s' % old_pkg],
[1890]46                          cwd='%s.git' % old_pkg)
[1880]47
48def mergeHistories():
[1884]49    merges = []
50    for line in open('merges'):
[1880]51        line = line.strip()
[1889]52        if line == '' or line[0] == '#':
[1880]53            continue
54       
[1884]55        merges.append(line.split())
[1883]56   
[1884]57    for merge in merges:
58        mergeHistory(*merge)
[1880]59
[1866]60if __name__ == '__main__':
61    try:
62        base = sys.argv[1]
63    except:
64        base = 'svn://invirt.mit.edu/trunk'
65   
66    cloneAllPackages(base)
[1880]67    mergeHistories()
Note: See TracBrowser for help on using the repository browser.