Пример #1
0
def get_raw(repo_key, branch_or_tag_or_sha, file_path):
    repo = get_repo(repo_key)
    commit = get_commit_for_refspec(repo, branch_or_tag_or_sha)
    tree = get_tree(repo, commit.tree.id)
    data = get_raw_file_content(repo, tree, file_path)
    mime_type = guess_mime_type(os.path.basename(file_path), data)
    if mime_type is None:
        mime_type = mime_types.OCTET_STREAM
    return Response(data, mimetype=mime_type)
Пример #2
0
def get_raw(repo_key, branch_or_tag_or_sha, file_path):
    repo = get_repo(repo_key)
    commit = get_commit_for_refspec(repo, branch_or_tag_or_sha)
    tree = get_tree(repo, commit.tree.id)
    data = get_raw_file_content(repo, tree, file_path)
    mime_type = guess_mime_type(os.path.basename(file_path), data)
    if mime_type is None:
        mime_type = mime_types.OCTET_STREAM
    return Response(data, mimetype=mime_type)
Пример #3
0
def get_blame(repo_key, branch_or_tag_or_sha, file_path):
    min_line = request.args.get('firstLine')
    if min_line is None:
        min_line = 1
    try:
        min_line = int(min_line)
    except ValueError:
        raise BadRequest("firstLine was not a valid integer")
    if min_line < 1:
        raise BadRequest("firstLine must be positive")

    max_line = request.args.get('lastLine')
    if max_line is not None:
        try:
            max_line = int(max_line)
        except ValueError:
            raise BadRequest("lastLine was not a valid integer")
        if max_line < 1:
            raise BadRequest("lastLine must be positive")

        if min_line > max_line:
            raise BadRequest("firstLine cannot be greater than lastLine")

    repo = get_repo(repo_key)
    newest_commit = get_commit_for_refspec(repo, branch_or_tag_or_sha)
    tree = get_tree(repo, newest_commit.tree_id)

    raw_lines = get_raw_file_content(repo, tree, file_path).splitlines()
    if min_line > len(raw_lines):
        raise BadRequest("firstLine out of bounds")
    if max_line is not None and max_line > len(raw_lines):
        raise BadRequest("lastLine out of bounds")
    raw_lines = raw_lines[(min_line - 1):max_line]

    blame = _get_blame(
        repo,
        file_path,
        newest_commit,
        oldest_refspec=request.args.get('oldest'),
        min_line=min_line,
        max_line=max_line,
    )

    return convert_blame(repo_key, repo, blame, raw_lines, min_line)
Пример #4
0
def get_blame(repo_key, branch_or_tag_or_sha, file_path):
    min_line = request.args.get('firstLine')
    if min_line is None:
        min_line = 1
    try:
        min_line = int(min_line)
    except ValueError:
        raise BadRequest("firstLine was not a valid integer")
    if min_line < 1:
        raise BadRequest("firstLine must be positive")

    max_line = request.args.get('lastLine')
    if max_line is not None:
        try:
            max_line = int(max_line)
        except ValueError:
            raise BadRequest("lastLine was not a valid integer")
        if max_line < 1:
            raise BadRequest("lastLine must be positive")

        if min_line > max_line:
            raise BadRequest("firstLine cannot be greater than lastLine")

    repo = get_repo(repo_key)
    newest_commit = get_commit_for_refspec(repo, branch_or_tag_or_sha)
    tree = get_tree(repo, newest_commit.tree_id)

    raw_lines = get_raw_file_content(repo, tree, file_path).splitlines()
    if min_line > len(raw_lines):
        raise BadRequest("firstLine out of bounds")
    if max_line is not None and max_line > len(raw_lines):
        raise BadRequest("lastLine out of bounds")
    raw_lines = raw_lines[(min_line - 1):max_line]

    blame = _get_blame(
        repo,
        file_path,
        newest_commit,
        oldest_refspec=request.args.get('oldest'),
        min_line=min_line,
        max_line=max_line,
    )

    return convert_blame(repo_key, repo, blame, raw_lines, min_line)