From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sat, 16 Jun 2018 15:38:09 +0100 Subject: [PATCH 08/11] ui-tree: print_object: add is_inline param In-Reply-To: <152885533059.7253.10994924042450989298.stgit@mail.warmcat.com> References: <152885510454.7253.3542488576272033383.stgit@mail.warmcat.com> <152885533059.7253.10994924042450989298.stgit@mail.warmcat.com> Message-ID: <20180616143809.GW1922@john.keeping.me.uk> 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 > --- > 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; >