| Index: git_common.py
|
| diff --git a/git_common.py b/git_common.py
|
| index 1215d9cd41d44385f98583c884188b006b8561f1..b5338252c5d24036e8d27e19cce6e393ee334ade 100644
|
| --- a/git_common.py
|
| +++ b/git_common.py
|
| @@ -29,6 +29,8 @@ import subprocess2
|
|
|
| GIT_EXE = 'git.bat' if sys.platform.startswith('win') else 'git'
|
|
|
| +NO_BRANCH = ('* (no branch)', '* (detached from ')
|
| +
|
|
|
| class BadCommitRefException(Exception):
|
| def __init__(self, refs):
|
| @@ -199,6 +201,28 @@ class ProgressPrinter(object):
|
| del self._thread
|
|
|
|
|
| +def abbrev(ref):
|
| + return run('rev-parse', '--abbrev-ref', ref)
|
| +
|
| +
|
| +def branches(*args):
|
| + for line in run('branch', *args).splitlines():
|
| + if line.startswith(NO_BRANCH):
|
| + continue
|
| + yield line.split()[-1]
|
| +
|
| +
|
| +def config_list(option):
|
| + try:
|
| + return run('config', '--get-all', option).split()
|
| + except subprocess2.CalledProcessError:
|
| + return []
|
| +
|
| +
|
| +def current_branch():
|
| + return abbrev('HEAD')
|
| +
|
| +
|
| def parse_commitrefs(*commitrefs):
|
| """Returns binary encoded commit hashes for one or more commitrefs.
|
|
|
| @@ -208,7 +232,7 @@ def parse_commitrefs(*commitrefs):
|
| * 'cool_branch~2'
|
| """
|
| try:
|
| - return map(binascii.unhexlify, hashes(*commitrefs))
|
| + return map(binascii.unhexlify, hash_multi(*commitrefs))
|
| except subprocess2.CalledProcessError:
|
| raise BadCommitRefException(commitrefs)
|
|
|
| @@ -231,7 +255,11 @@ def run(*cmd, **kwargs):
|
| return ret
|
|
|
|
|
| -def hashes(*reflike):
|
| +def hash_one(reflike):
|
| + return run('rev-parse', reflike)
|
| +
|
| +
|
| +def hash_multi(*reflike):
|
| return run('rev-parse', *reflike).splitlines()
|
|
|
|
|
| @@ -249,6 +277,13 @@ def intern_f(f, kind='blob'):
|
| return ret
|
|
|
|
|
| +def tags(*args):
|
| + for line in run('tag', *args).splitlines():
|
| + if line.startswith(NO_BRANCH):
|
| + continue
|
| + yield line.split()[-1]
|
| +
|
| +
|
| def tree(treeref, recurse=False):
|
| """Returns a dict representation of a git tree object.
|
|
|
| @@ -286,6 +321,14 @@ def tree(treeref, recurse=False):
|
| return ret
|
|
|
|
|
| +def upstream(branch):
|
| + try:
|
| + return run('rev-parse', '--abbrev-ref', '--symbolic-full-name',
|
| + branch+'@{upstream}')
|
| + except subprocess2.CalledProcessError:
|
| + return None
|
| +
|
| +
|
| def mktree(treedict):
|
| """Makes a git tree object and returns its hash.
|
|
|
|
|