From mboxrd@z Thu Jan 1 00:00:00 1970 From: andy at warmcat.com (Andy Green) Date: Wed, 20 Jun 2018 08:00:45 +0800 Subject: [PATCH v3 12/17] ui-tree: render any matching README file in tree view In-Reply-To: <20180619214944.GC1922@john.keeping.me.uk> References: <152939875224.4492.4288866616332837866.stgit@mail.warmcat.com> <152939894744.4492.11356984456749404081.stgit@mail.warmcat.com> <20180619214944.GC1922@john.keeping.me.uk> Message-ID: <3ca574ca-4f3d-96e0-304b-cc1ceb4d087f@warmcat.com> On 06/20/2018 05:49 AM, John Keeping wrote: > On Tue, Jun 19, 2018 at 05:02:27PM +0800, Andy Green wrote: >> While listing the items in tree view, we collect a list >> of any filenames that match any tree-readme entries from the >> config file. >> >> After the tree view has been shown, we iterate through any >> collected readme files rendering them inline. > > There's only one now, the commit message isn't quite accurate any more! Right... the name changed as well... I updated it. -Andy >> Signed-off-by: Andy Green >> Reviewed-by: John Keeping >> --- >> ui-tree.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 52 insertions(+), 1 deletion(-) >> >> diff --git a/ui-tree.c b/ui-tree.c >> index 1ccbb22..6ffd4dd 100644 >> --- a/ui-tree.c >> +++ b/ui-tree.c >> @@ -1,6 +1,6 @@ >> /* ui-tree.c: functions for tree output >> * >> - * Copyright (C) 2006-2017 cgit Development Team >> + * Copyright (C) 2006-2018 cgit Development Team >> * >> * Licensed under GNU General Public License v2 >> * (see COPYING for full license text) >> @@ -12,8 +12,10 @@ >> #include "ui-shared.h" >> >> struct walk_tree_context { >> + struct object_id inline_oid; >> char *curr_rev; >> char *match_path; >> + char *inline_filename; >> int state; >> bool use_render; >> }; >> @@ -325,11 +327,19 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, >> &fullpath); >> } else { >> char *ext = strrchr(name, '.'); >> + >> strbuf_addstr(&class, "ls-blob"); >> if (ext) >> strbuf_addf(&class, " %s", ext + 1); >> + >> cgit_tree_link(name, NULL, class.buf, ctx.qry.head, >> walk_tree_ctx->curr_rev, fullpath.buf); >> + >> + if (!walk_tree_ctx->inline_filename && >> + string_list_has_string(&ctx.repo->inline_readme, name)) { >> + walk_tree_ctx->inline_filename = xstrdup(pathname); >> + oidcpy(&walk_tree_ctx->inline_oid, oid); >> + } >> } >> htmlf("%li", size); >> >> @@ -367,7 +377,46 @@ static void ls_head(void) >> >> static void ls_tail(struct walk_tree_context *walk_tree_ctx) >> { >> + struct cgit_filter *render; >> + enum object_type type; >> + char *buf, *mimetype; >> + unsigned long size; >> + >> html("\n"); >> + >> + if (!walk_tree_ctx->inline_filename) >> + goto done; >> + >> + type = oid_object_info(the_repository, &walk_tree_ctx->inline_oid, &size); >> + if (type == OBJ_BAD) >> + goto done; >> + >> + buf = read_object_file(&walk_tree_ctx->inline_oid, &type, &size); >> + if (!buf) >> + goto done; >> + >> + /* create a vertical gap between tree nav / inline */ >> + html("
"); >> + >> + render = get_render_for_filename(walk_tree_ctx->inline_filename); >> + mimetype = render ? NULL : get_mimetype_for_filename( >> + walk_tree_ctx->inline_filename); >> + >> + htmlf("

%s

", walk_tree_ctx->inline_filename); >> + html("
 
\n"); >> + >> + if (render) >> + render_buffer(render, walk_tree_ctx->inline_filename, >> + buf, size); >> + else if (mimetype) >> + include_file(walk_tree_ctx->inline_filename, mimetype); >> + else >> + print_buffer(walk_tree_ctx->inline_filename, buf, size); >> + >> + free(mimetype); >> + free(buf); >> + >> +done: >> cgit_print_layout_end(); >> } >> >> @@ -478,4 +527,6 @@ void cgit_print_tree(const char *rev, char *path, bool use_render) >> >> cleanup: >> free(walk_tree_ctx.curr_rev); >> + if (walk_tree_ctx.inline_filename) >> + free(walk_tree_ctx.inline_filename); >> } >> >> _______________________________________________ >> CGit mailing list >> CGit at lists.zx2c4.com >> https://lists.zx2c4.com/mailman/listinfo/cgit