diff options
| author | Patrick | 2025-12-23 23:35:13 +0100 |
|---|---|---|
| committer | Patrick | 2025-12-23 23:35:13 +0100 |
| commit | 7dfc2b975fd4a735073536914f5a49b8d80a1104 (patch) | |
| tree | 69ec9e78cd5ad255ae17435f962952a1e4ebdc2c /ui-summary.c | |
| parent | 13ff15345e1fe7ecc72967e1e0d9a473428f241f (diff) | |
| download | ps-cgit-7dfc2b975fd4a735073536914f5a49b8d80a1104.tar.gz ps-cgit-7dfc2b975fd4a735073536914f5a49b8d80a1104.zip | |
buncha features
Diffstat (limited to 'ui-summary.c')
| -rw-r--r-- | ui-summary.c | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/ui-summary.c b/ui-summary.c index b3e5cc6..bf75039 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -155,42 +155,69 @@ done: // int stage, const struct pathspec *pathspec, // read_tree_fn_t fn, void *context); struct get_readme_oid_ctx { - const struct object_id *oid; + struct object_id *oid; char **filename; + const char *path; + bool found; }; static int get_readme_oid_cb(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { + struct get_readme_oid_ctx *ctx = (struct get_readme_oid_ctx*)cbdata; + // TODO: make readme.md configurable const char *readme_name = "readme.md"; - html(pathname); - if (strcmp(pathname, readme_name) == 0) { - struct get_readme_oid_ctx *ctx = (struct get_readme_oid_ctx*)cbdata; - ctx->oid = oid; + + struct strbuf buffer = STRBUF_INIT; + if (base->len > 0) + strbuf_addbuf(&buffer, base); + + bool match_base = false; + if (ctx->path == NULL) + match_base = base->len == 0; + else if (strncmp(buffer.buf, ctx->path, buffer.len > 0 ? buffer.len - 1 : 0) == 0) + match_base = true; + + strbuf_addstr(&buffer, pathname); + + bool match_path = false; + if (ctx->path == NULL) + match_path = false; + else if (strcmp(buffer.buf, ctx->path) == 0) + match_path = true; + + strbuf_release(&buffer); + + if (match_base && strcmp(pathname, readme_name) == 0) { + *(ctx->oid) = *oid; *(ctx->filename) = xstrdup(pathname); - // TODO: maybe skip by returning != 0 + ctx->found = true; + } + else if (match_path) { + return READ_TREE_RECURSIVE; } return 0; } -const struct object_id * get_readme_oid(const struct tree *tree, char **filename) { - struct pathspec paths = { - .nr = 0 - }; - struct get_readme_oid_ctx ctx = { NULL, filename }; - read_tree_recursive(the_repository, tree, "", 0, 1, - &paths, get_readme_oid_cb, &ctx); - return ctx.oid; +bool get_readme_oid(const struct tree *tree, struct pathspec *paths, struct object_id *oid, char **filename) { + struct get_readme_oid_ctx gro_ctx = (struct get_readme_oid_ctx){ + .oid = oid, + .filename = filename, + .path = (paths->nr == 1 ? paths->items[0].match : NULL), + .found = false }; + read_tree_recursive(the_repository, tree, "", 0, 0, + paths, get_readme_oid_cb, &gro_ctx); + return gro_ctx.found; } -void cgit_print_repo_readme_no_layout(const struct tree *tree) +void cgit_print_repo_readme_no_layout(const struct tree *tree, struct pathspec *paths) { char *filename = NULL; - const struct object_id *readme_oid = get_readme_oid(tree, &filename); - if (readme_oid) { + struct object_id readme_oid; + if (get_readme_oid(tree, paths, &readme_oid, &filename)) { html("<div id='summary'>"); cgit_open_filter(ctx.repo->about_filter, filename); - cgit_print_oid(readme_oid); + cgit_print_oid(&readme_oid); cgit_close_filter(ctx.repo->about_filter); html("</div>"); |
