Пример #1
0
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == '/':
        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(request, 'repositories/repository_tree.html', {
            'repository': repo,
            'commit': commit,
            'tree': tree,
            'breadcrumb': build_path_breadcrumb(path)
        })

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(
            path.rsplit('.', 1)[-1], file_obj.content)

        return render(request, 'repositories/repository_file.html', {
            'repository': repo,
            'commit': commit,
            'file_path': path,
            'file_obj': file_obj,
            'file_lines': range(1, file_obj.content.count('\n') + 1),
            'file_blob_pygmentized': file_blob_pygmentized,
            'breadcrumb': build_path_breadcrumb(path)
        })
Пример #2
0
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == "/":
        if request.is_ajax() and "commits" in request.GET:
            tree = commit.get_tree(path, commits=True).tree
            tree_elements = []
            for entry in tree:
                tree_elements.append(
                    {
                        "tree_id": entry["sha"],
                        "id": entry["commit"].id,
                        "author": entry["commit"].author,
                        "commit_date": entry["commit"].commit_date,
                        "since": timesince(entry["commit"].commit_date),
                    }
                )
            return HttpResponse(simplejson.dumps(tree_elements, cls=DjangoJSONEncoder), mimetype="application/json")

        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(
            request,
            "repositories/repository_tree.html",
            {"repository": repo, "commit": commit, "tree": tree, "breadcrumb": build_path_breadcrumb(path)},
        )

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(path.rsplit(".", 1)[-1], file_obj.content)

        return render(
            request,
            "repositories/repository_file.html",
            {
                "repository": repo,
                "commit": commit,
                "file_path": path,
                "file_obj": file_obj,
                "file_lines": range(1, file_obj.content.count("\n") + 1),
                "file_blob_pygmentized": file_blob_pygmentized,
                "breadcrumb": build_path_breadcrumb(path),
            },
        )
Пример #3
0
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == '/':
        if request.is_ajax() and 'commits' in request.GET:
            tree = commit.get_tree(path, commits=True).tree
            tree_elements = []
            for entry in tree:
                tree_elements.append({
                    'tree_id': entry['sha'],
                    'id': entry['commit'].id,
                    'author': entry['commit'].author,
                    'commit_date': entry['commit'].commit_date,
                    'since': timesince(entry['commit'].commit_date),
                })
            return HttpResponse(simplejson.dumps(tree_elements,
                cls=DjangoJSONEncoder), mimetype='application/json')

        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(request, 'repositories/repository_tree.html', {
            'repository': repo,
            'commit': commit,
            'tree': tree,
            'breadcrumb': build_path_breadcrumb(path)
        })

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(
            path.rsplit('.', 1)[-1], file_obj.content)

        return render(request, 'repositories/repository_file.html', {
            'repository': repo,
            'commit': commit,
            'file_path': path,
            'file_obj': file_obj,
            'file_lines': range(1, file_obj.content.count('\n') + 1),
            'file_blob_pygmentized': file_blob_pygmentized,
            'breadcrumb': build_path_breadcrumb(path)
        })
Пример #4
0
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == '/':
        if request.is_ajax() and 'commits' in request.GET:
            tree = commit.get_tree(path, commits=True).tree
            tree_elements = []
            for entry in tree:
                tree_elements.append({
                    'tree_id': entry['sha'],
                    'id': entry['commit'].id,
                    'author': entry['commit'].author,
                    'commit_date': entry['commit'].commit_date,
                    'since': timesince(entry['commit'].commit_date),
                })
            return HttpResponse(simplejson.dumps(tree_elements,
                cls=DjangoJSONEncoder), mimetype='application/json')

        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(request, 'repositories/repository_tree.html', {
            'repository': repo,
            'commit': commit,
            'tree': tree,
            'breadcrumb': build_path_breadcrumb(path)
        })

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(
            path.rsplit('.', 1)[-1], file_obj.content)

        return render(request, 'repositories/repository_file.html', {
            'repository': repo,
            'commit': commit,
            'file_path': path,
            'file_obj': file_obj,
            'file_lines': range(1, file_obj.content.count('\n') + 1),
            'file_blob_pygmentized': file_blob_pygmentized,
            'breadcrumb': build_path_breadcrumb(path)
        })
Пример #5
0
def pygmentize_diff(blob):
    try:
        return pygmentize('diff', blob)
    except:
        return blob
Пример #6
0
def pygmentize_diff(blob):
    try:
        return pygmentize('diff', blob)
    except:
        return blob