Example #1
0
def tree(ctx, rev, path):
    if rev == "HEAD":
        commit_obj = ctx.odb.head
    elif rev == "index":
        commit_obj = ctx.odb.index
        if commit_obj is None:
            raise NotFound("No such file or directory")
    else:
        commit_obj = ctx.odb.get_commit(rev)

    try:
        tree_obj = commit_obj.tree[path]

    except KeyError:
        raise NotFound("No such file or directory")

    if not isinstance(tree_obj, TreeObject):
        raise NotFound("No such file or directory")

    readme_obj = utils.find_readme(tree_obj)
    if readme_obj is not None:
        readme_doc = render_blob(ctx, readme_obj)
        readme = ctx.render_template("readme.html", doc=readme_doc)

    else:
        readme = None

    return ctx.render_to_response("tree.html", commit=commit_obj, tree=tree_obj, readme=readme)
Example #2
0
def title(context, obj):
    ctx = context['context']

    if isinstance(obj, BlobObject):
        doc = render_blob(ctx, obj)
        return doc.title

    elif isinstance(obj, TreeObject):
        readme_obj = utils.find_readme(obj)
        if readme_obj is not None:
            readme_doc = render_blob(ctx, readme_obj)
            return readme_doc.title

    else:
        # TODO: LinkObject
        pass