| Index: git_common.py
|
| diff --git a/git_common.py b/git_common.py
|
| index 6952c1ee318765ebe40622ec9a7b5d10334c888f..2266502838f11080ec6eb968edecafc0e14f538a 100644
|
| --- a/git_common.py
|
| +++ b/git_common.py
|
| @@ -30,6 +30,8 @@ import threading
|
|
|
| import subprocess2
|
|
|
| +import git_cache
|
| +
|
|
|
| GIT_EXE = 'git.bat' if sys.platform.startswith('win') else 'git'
|
| TEST_MODE = False
|
| @@ -215,9 +217,10 @@ def once(function):
|
| """@Decorates |function| so that it only performs its action once, no matter
|
| how many times the decorated |function| is called."""
|
| def _inner_gen():
|
| - yield function()
|
| + ret = function()
|
| + yield ret
|
| while True:
|
| - yield
|
| + yield ret
|
| return _inner_gen().next
|
|
|
|
|
| @@ -275,6 +278,23 @@ def run_with_retcode(*cmd, **kwargs):
|
| return cpe.returncode
|
|
|
|
|
| +def cached_fetch(commits):
|
| + m = git_cache.Mirror.from_repo('.')
|
| + if m:
|
| + m.populate(fetch_specs=commits)
|
| + else:
|
| + for commit in commits:
|
| + run('fetch', 'origin', commit)
|
| +
|
| +
|
| +def check(*args, **kwargs):
|
| + try:
|
| + run(*args, **kwargs)
|
| + return True
|
| + except subprocess2.CalledProcessError:
|
| + return False
|
| +
|
| +
|
| def config(option, default=None):
|
| try:
|
| return run('config', '--get', option) or default
|
| @@ -375,6 +395,14 @@ def get_or_create_merge_base(branch, parent=None):
|
| return base
|
|
|
|
|
| +def get_remote_url(remote):
|
| + m = git_cache.Mirror.from_repo('.')
|
| + if m:
|
| + return m.url
|
| +
|
| + return config('remote.%s.url' % remote)
|
| +
|
| +
|
| def hash_multi(*reflike):
|
| return run('rev-parse', *reflike).splitlines()
|
|
|
| @@ -512,9 +540,12 @@ def run_with_stderr(*cmd, **kwargs):
|
| kwargs.setdefault('stdout', subprocess2.PIPE)
|
| kwargs.setdefault('stderr', subprocess2.PIPE)
|
| autostrip = kwargs.pop('autostrip', True)
|
| + verbose = kwargs.pop('verbose', False)
|
| indata = kwargs.pop('indata', None)
|
|
|
| cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
|
| + if verbose:
|
| + print "running `%s`" % (cmd,)
|
| proc = subprocess2.Popen(cmd, **kwargs)
|
| ret, err = proc.communicate(indata)
|
| retcode = proc.wait()
|
| @@ -657,3 +688,7 @@ def upstream(branch):
|
| branch+'@{upstream}')
|
| except subprocess2.CalledProcessError:
|
| return None
|
| +
|
| +
|
| +def verify_commit(commit):
|
| + return check('rev-parse', '--quiet', '--verify', '%s^{commit}' % commit)
|
|
|