#! /usr/bin/env python import os, re, subprocess, sys silent = False git_dir = os.path.join(os.getenv('HOME'), 'gsrc', 'linux-2.6', '.git') os.putenv('GIT_DIR', git_dir) devnull = open('/dev/null', 'w', 0) if silent: subprocess_stdout = devnull else: subprocess_stdout = None if not silent: print 'fetch origin' subprocess.call(['git-fetch', 'origin'], stdout=subprocess_stdout) sp_describe = subprocess.Popen(['git-describe', 'origin'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) sp_describe_stdin, sp_describe_stderr = sp_describe.communicate() re_linuxver = re.compile('v2\.6\.(?P\d+)(?P\.\d+)?(?P-rc\d+)?(?P-g[0-9a-fA-F]+)?') mo = re_linuxver.match(sp_describe_stdin) if not mo: print 'cannot parse version of origin\'s HEAD' sys.exit(1) modict = mo.groupdict() if modict['rc'] and not modict['stable']: last_stable = int(modict['minor']) - 1 else: last_stable = int(modict['minor']) for stable in (16, last_stable - 1, last_stable): if subprocess.call(['git', 'repo-config', 'remote.v2.6.%d.y.url' % stable], stdout=devnull) != 0: subprocess.call(['git', 'repo-config', 'remote.v2.6.%d.y.url' % stable, 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-2.6.%d.y.git' % stable]) subprocess.call(['git', 'repo-config', 'remote.v2.6.%d.y.fetch' % stable, 'refs/heads/master:refs/remotes/stable/v2.6.%d.y' % stable]) subprocess.call(['git', 'repo-config', 'branch.v2.6.%d.y.remote' % stable, 'v2.6.%d.y' % stable]) subprocess.call(['git', 'repo-config', 'branch.v2.6.%d.y.remote' % stable, 'v2.6.%d.y' % stable]) subprocess.call(['git', 'repo-config', 'branch.v2.6.%d.y.merge' % stable, 'refs/heads/master']) if not silent: print 'fetch v2.6.%d.y' % stable subprocess.call(['git-fetch', 'v2.6.%d.y' % stable], stdout=subprocess_stdout)