[PATCH 08/11] ui-tree: print_object: add is_inline param
John Keeping
john at keeping.me.uk
Sat Jun 16 16:38:09 CEST 2018
On Wed, Jun 13, 2018 at 10:02:10AM +0800, Andy Green wrote:
> We will reuse print_object to render things inline shortly.
>
> Add a parameter that lets us adapt its behaviour slightly
> for that case.
>
> Signed-off-by: Andy Green <andy at warmcat.com>
> ---
> ui-tree.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/ui-tree.c b/ui-tree.c
> index fe5dc75..bb10b17 100644
> --- a/ui-tree.c
> +++ b/ui-tree.c
> @@ -158,7 +158,7 @@ static void include_file(const unsigned char *sha1, const char *path,
> }
>
> static void print_object(const unsigned char *sha1, char *path, const char *basename,
> - const char *rev, bool use_render)
> + const char *rev, bool use_render, bool is_inline)
I don't think this is the right way to handle this. There's other
behaviour here that needs to be suppressed if this is inline content,
such as the call to cgit_set_title_from_path(), and I don't think we
want the object header above the readme content.
Additionally, if read_sha1_file() fails we'll output another page header
here.
Since it's not much code overall, I think we probably don't want to
reuse print_object() for the inline rendering, but can instead just do
the render & mimetype lookup and then do:
if (render)
render_buffer(render, basename, buf, size);
else if (mimetype)
include_file(sha1, path, mimetype);
else
print_buffer(basename, buf, size);
> {
> enum object_type type;
> struct cgit_filter *render;
> @@ -191,7 +191,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
> if (!render && !mimetype)
> use_render = false;
>
> - cgit_print_layout_start();
> + if (!is_inline)
> + cgit_print_layout_start();
> htmlf("blob: %s (", sha1_to_hex(sha1));
> cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
> rev, path);
> @@ -415,7 +416,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
> } else {
> walk_tree_ctx->state = 2;
> print_object(sha1, buffer.buf, pathname, walk_tree_ctx->curr_rev,
> - walk_tree_ctx->use_render);
> + walk_tree_ctx->use_render, 0);
> strbuf_release(&buffer);
>
> return 0;
>
More information about the CGit
mailing list