Ejemplo 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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def get_commit_for_refspec(repo, branch_or_tag_or_sha):
    # Precedence order GitHub uses (& that we copy):
    # 1. Branch  2. Tag  3. Commit SHA
    commit_sha = None
    # branch?
    branch_ref = lookup_ref(repo, branch_or_tag_or_sha)
    if branch_ref is not None:
        commit_sha = branch_ref.resolve().target.hex
    # tag?
    if commit_sha is None:
        ref_to_tag = lookup_ref(repo, "tags/" + branch_or_tag_or_sha)
        if ref_to_tag is not None:
            commit_sha = ref_to_tag.get_object().hex
    # commit?
    if commit_sha is None:
        commit_sha = branch_or_tag_or_sha
    try:
        return get_commit(repo, commit_sha)
    except (ValueError, NotFound):
        raise NotFound("no such branch, tag, or commit SHA")
Ejemplo n.º 4
0
def get_commit_for_refspec(repo, branch_or_tag_or_sha):
    # Precedence order GitHub uses (& that we copy):
    # 1. Branch  2. Tag  3. Commit SHA
    commit_sha = None
    # branch?
    branch_ref = lookup_ref(repo, branch_or_tag_or_sha)
    if branch_ref is not None:
        commit_sha = branch_ref.resolve().target
    # tag?
    if commit_sha is None:
        ref_to_tag = lookup_ref(repo, "tags/" + branch_or_tag_or_sha)
        if ref_to_tag is not None:
            commit_sha = ref_to_tag.get_object().id
    # commit?
    if commit_sha is None:
        commit_sha = branch_or_tag_or_sha
    try:
        return get_commit(repo, commit_sha)
    except (ValueError, NotFound):
        raise NotFound("no such branch, tag, or commit SHA")
Ejemplo n.º 5
0
def get_tag(repo_key, tag_name):  # NOTE: This endpoint is a RestfulGit extension
    repo = get_repo(repo_key)
    tag = lookup_ref(repo, TAG_REF_PREFIX + tag_name)
    if tag is None:
        raise NotFound("tag not found")
    result = {
        "name": tag.shorthand,
        "commit": convert_commit(repo_key, repo, tag.get_object()),
        "url": url_for("porcelain.get_tag", _external=True, repo_key=repo_key, tag_name=tag.shorthand),
    }
    # simple tag
    if tag.target != tag.get_object().id:
        tag_obj = repo[tag.target]
        result["tag"] = convert_tag(repo_key, repo, tag_obj)
    return result
Ejemplo n.º 6
0
def get_tag(repo_key, tag_name):  # NOTE: This endpoint is a RestfulGit extension
    repo = get_repo(repo_key)
    tag = lookup_ref(repo, TAG_REF_PREFIX + tag_name)
    if tag is None:
        raise NotFound("tag not found")
    result = {
        "name": tag.shorthand,
        "commit": convert_commit(repo_key, repo, tag.peel()),
        "url": url_for('porcelain.get_tag', _external=True,
                       repo_key=repo_key, tag_name=tag.shorthand),
    }
    # simple tag
    if tag.target != tag.peel().id:
        tag_obj = repo[tag.target]
        result['tag'] = convert_tag(repo_key, repo, tag_obj)
    return result