Changeset 1893 for trunk/scripts


Ignore:
Timestamp:
Dec 24, 2008, 11:33:27 PM (15 years ago)
Author:
broder
Message:

Here's a version that's more likely to work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/git-migration/git-migrate

    r1892 r1893  
    55import subprocess
    66import shutil
     7
     8def tagBase(pkg):
     9    p = subprocess.Popen(['git', 'tag',
     10                          '-l',
     11                          'base'],
     12                         cwd='%s.git' % pkg,
     13                         stdout=subprocess.PIPE)
     14    p.wait()
     15    if p.stdout.read().strip() != '':
     16        return
     17   
     18    p = subprocess.Popen(['git', 'rev-list',
     19                          '--reverse',
     20                          'master'],
     21                         cwd='%s.git' % pkg,
     22                         stdout=subprocess.PIPE)
     23    p.wait()
     24    base = p.stdout.read().split()[0]
     25   
     26    subprocess.check_call(['git', 'tag',
     27                           'base',
     28                           base],
     29                          cwd='%s.git' % pkg)
    730
    831def clonePackage(base, pkg):
     
    3558        subprocess.check_call(['git', 'reset', '--soft', 'HEAD^'],
    3659                              cwd='%s.git' % pkg)
     60   
     61    tagBase(pkg)
    3762
    3863def cloneAllPackages(base):
     
    4166
    4267def mergeHistory(old_pkg, new_pkg, n):
     68    n = int(n)
     69   
    4370    subprocess.check_call(['git', 'push',
    4471                           '../%s.git' % new_pkg,
    4572                           'master:refs/heads/%s' % old_pkg],
    4673                          cwd='%s.git' % old_pkg)
     74   
     75    # Find the merge commit
     76    if n == 0:
     77        p = subprocess.Popen(['git', 'rev-parse',
     78                              'base'],
     79                             cwd='%s.git' % new_pkg,
     80                             stdout=subprocess.PIPE)
     81    else:
     82        p = subprocess.Popen(['git', 'rev-list',
     83                              '--reverse',
     84                              '--boundary',
     85                              '--skip=%s' % (n - 1),
     86                              'base..master'],
     87                             cwd='%s.git' % new_pkg,
     88                             stdout=subprocess.PIPE)
     89    p.wait()
     90    new_rev = p.stdout.read().split()[0].strip('-')
     91   
     92    # Find any other parents of the merge commit
     93    p = subprocess.Popen(['git', 'log',
     94                          '-1',
     95                          '--pretty=format:%P',
     96                          new_rev],
     97                         cwd='%s.git' % new_pkg,
     98                         stdout=subprocess.PIPE)
     99    p.wait()
     100    parents = p.stdout.read().split()
     101   
     102    # Find the additional parent we're adding
     103    p = subprocess.Popen(['git', 'rev-parse',
     104                          old_pkg],
     105                         cwd='%s.git' % new_pkg,
     106                         stdout=subprocess.PIPE)
     107    p.wait()
     108    parents.append(p.stdout.read().strip())
     109   
     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))
     113    f.close()
     114   
     115    # Run filter-branch
     116    subprocess.call(['git', 'filter-branch',
     117                     '--tag-name-filter', 'cat',
     118                     '--',
     119                     '--all'],
     120                    cwd='%s.git' % new_pkg)
    47121
    48122def mergeHistories():
Note: See TracChangeset for help on using the changeset viewer.