Esempio n. 1
0
def get_commit_list(repo_key):
    ref_name = request.args.get('ref_name') or None
    start_sha = request.args.get('start_sha') or None
    limit = request.args.get('limit') or current_app.config['RESTFULGIT_DEFAULT_COMMIT_LIST_LIMIT']
    try:
        limit = int(limit)
    except ValueError:
        raise BadRequest("invalid limit")
    if limit < 0:
        raise BadRequest("invalid limit")

    repo = get_repo(repo_key)

    start_commit_id = None
    if start_sha is not None:
        start_commit_id = start_sha
    else:
        if ref_name is None:
            ref_name = "HEAD"
        ref = lookup_ref(repo, ref_name)
        if ref is None:
            raise NotFound("reference not found")
        start_commit_id = lookup_ref(repo, ref_name).resolve().target

    try:
        walker = repo.walk(start_commit_id, GIT_SORT_TIME)
    except ValueError:
        raise BadRequest("invalid start_sha")
    except KeyError:
        raise NotFound("commit not found")

    commits = [convert_commit(repo_key, commit) for commit in islice(walker, limit)]
    return commits
Esempio n. 2
0
def get_merge_base_for_commits(repo_key, left_sha, right_sha):  # NOTE: RestfulGit extension
    repo = get_repo(repo_key)
    left_commit = _get_commit(repo, left_sha)
    right_commit = _get_commit(repo, right_sha)
    try:
        merge_base_oid = repo.merge_base(left_commit.id, right_commit.id)
        merge_base_commit = repo[merge_base_oid]
    except KeyError:
        return None
    else:
        return convert_commit(repo_key, merge_base_commit)
Esempio n. 3
0
def get_merge_base_for_commits(repo_key, left_sha,
                               right_sha):  # NOTE: RestfulGit extension
    repo = get_repo(repo_key)
    left_commit = _get_commit(repo, left_sha)
    right_commit = _get_commit(repo, right_sha)
    try:
        merge_base_oid = repo.merge_base(left_commit.id, right_commit.id)
        merge_base_commit = repo[merge_base_oid]
    except TypeError:
        return None
    else:
        return convert_commit(repo_key, merge_base_commit)
Esempio n. 4
0
def get_commit_list(repo_key):
    ref_name = request.args.get('ref_name') or None
    start_sha = request.args.get('start_sha') or None
    limit = request.args.get(
        'limit') or current_app.config['RESTFULGIT_DEFAULT_COMMIT_LIST_LIMIT']
    try:
        limit = int(limit)
    except ValueError:
        raise BadRequest("invalid limit")
    if limit < 0:
        raise BadRequest("invalid limit")

    repo = get_repo(repo_key)

    start_commit_id = None
    if start_sha is not None:
        start_commit_id = start_sha
    else:
        if ref_name is None:
            ref_name = "HEAD"
        ref = lookup_ref(repo, ref_name)
        if ref is None:
            raise NotFound("reference not found")
        start_ref = lookup_ref(repo, ref_name)
        try:
            start_commit_id = start_ref.resolve().target
        except KeyError:
            if ref_name == "HEAD":
                return []
            else:
                raise NotFound("reference not found")

    try:
        walker = repo.walk(start_commit_id, GIT_SORT_TIME)
    except ValueError:
        raise BadRequest("invalid start_sha")
    except KeyError:
        raise NotFound("commit not found")

    commits = [
        convert_commit(repo_key, commit) for commit in islice(walker, limit)
    ]
    return commits
Esempio n. 5
0
def get_commit(repo_key, sha):
    repo = get_repo(repo_key)
    commit = _get_commit(repo, sha)
    return convert_commit(repo_key, commit)
Esempio n. 6
0
def get_commit(repo_key, sha):
    repo = get_repo(repo_key)
    commit = _get_commit(repo, sha)
    return convert_commit(repo_key, commit)