Exemplo n.º 1
0
def repository_tree(request, id, slug, branch, path, template_name='gitweb/repository_tree.html'):
    try:
        repository = Repository.objects.visible_repositories_for_user(request.user).get(pk=id)
    except Repository.DoesNotExist:
        raise Http404

    tree = repository.repo().tree(branch)

    for element in path.split('/'):
        if len(element):
            tree = tree/element

    if hasattr(tree, 'mime_type'):
        is_blob = True
    else:
        is_blob = False
        tree = [{'path': os.path.join(path, e.name), 'e': e, 'human_size': human_filesize(getattr(e, 'size', 0))} for e in tree.values()]

    template_context = {
        'repository': repository,
        'branch': branch,
        'path': os.path.join('/', path),
        'prev_path': '/'.join(path.split('/')[0:-1]),
        'tree': tree,
        'is_blob': is_blob,
    }
    if is_blob:
        template_context.update({
            'blob_human_size': human_filesize(tree.size),
            'blob_lines': range(len(tree.data.splitlines())),
            'blob_pygmentized': pygmentize(tree.mime_type, tree.data),
        })

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )
Exemplo n.º 2
0
def pygmentize_diff(blob):
    try:
        return pygmentize('diff', blob)
    except:
        return blob