示例#1
0
文件: gitfs.py 项目: bemehow/salt
def _get_tree_pygit2(repo, short):
    """
    Return a pygit2.Tree object if the branch/tag/SHA is found, otherwise None
    """
    if short == __opts__["gitfs_base"] or short in envs():
        for ref in repo.listall_references():
            _, rtype, rspec = ref.split("/", 2)
            if rtype in ("remotes", "tags"):
                parted = rspec.partition("/")
                rspec = parted[2] if parted[2] else parted[0]
                rspec = rspec.replace("/", "_")
                if rspec == short and _env_is_exposed(rspec):
                    return repo.lookup_reference(ref).get_object().tree

    # Branch or tag not matched, check if 'short' is a commit
    if not _env_is_exposed(short):
        return None
    try:
        commit = repo.revparse_single(short)
    except (KeyError, TypeError):
        # Not a valid commit, likely not a commit SHA
        pass
    else:
        return commit.tree
    return None
示例#2
0
def _get_tree_pygit2(repo, short):
    '''
    Return a pygit2.Tree object if the branch/tag/SHA is found, otherwise None
    '''
    if short in envs():
        for ref in repo.listall_references():
            _, rtype, rspec = ref.split('/', 2)
            if rtype in ('remotes', 'tags'):
                parted = rspec.partition('/')
                rspec = parted[2] if parted[2] else parted[0]
                rspec = rspec.replace('/', '_')
                if rspec == short and _env_is_exposed(rspec):
                    return repo.lookup_reference(ref).get_object().tree

    # Branch or tag not matched, check if 'short' is a commit
    if not _env_is_exposed(short):
        return None
    try:
        commit = repo.revparse_single(short)
    except (KeyError, TypeError):
        # Not a valid commit, likely not a commit SHA
        pass
    else:
        return commit.tree
    return None
示例#3
0
def _envs_pygit2(repo, base_branch):
    '''
    Check the refs and return a list of the ones which can be used as salt
    environments.
    '''
    ret = set()
    remote = repo.remotes[0]
    stale_refs = _stale_refs_pygit2(repo)
    for ref in repo.listall_references():
        ref = re.sub('^refs/', '', ref)
        rtype, rspec = ref.split('/', 1)
        if rtype == 'tags':
            ret.add(rspec)
        elif rtype == 'remotes':
            if rspec not in stale_refs:
                parted = rspec.partition('/')
                short = parted[2] if parted[2] else parted[0]
                if short == base_branch:
                    short = 'base'
                ret.add(short)
    return ret
示例#4
0
文件: gitfs.py 项目: bemehow/salt
def _envs_pygit2(repo, base_branch):
    """
    Check the refs and return a list of the ones which can be used as salt
    environments.
    """
    ret = set()
    remote = repo.remotes[0]
    stale_refs = _stale_refs_pygit2(repo)
    for ref in repo.listall_references():
        ref = re.sub("^refs/", "", ref)
        rtype, rspec = ref.split("/", 1)
        if rtype == "remotes":
            if rspec not in stale_refs:
                parted = rspec.partition("/")
                rspec = parted[2] if parted[2] else parted[0]
                rspec = rspec.replace("/", "_")
                if rspec == base_branch:
                    rspec = "base"
                if _env_is_exposed(rspec):
                    ret.add(rspec)
        elif rtype == "tags" and _env_is_exposed(rspec):
            ret.add(rspec)
    return ret