abouttreesummaryrefslogcommitdiff
path: root/ui-summary.c
diff options
context:
space:
mode:
authorpatrick-scho2025-12-01 15:12:11 +0100
committerpatrick-scho2025-12-01 15:12:11 +0100
commit4bf7dacfa870fb1fb81edf647fd5c049786c3c2f (patch)
tree2b86ea0f899db22f467c82d13c37c01ee43abe11 /ui-summary.c
parent7b3024b827a667c8a50260c679ebdb39ef4b937a (diff)
downloadps-cgit-4bf7dacfa870fb1fb81edf647fd5c049786c3c2f.tar.gz
ps-cgit-4bf7dacfa870fb1fb81edf647fd5c049786c3c2f.zip
print readme by oid try 1
Diffstat (limited to 'ui-summary.c')
-rw-r--r--ui-summary.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/ui-summary.c b/ui-summary.c
index b5224f2..76f7df6 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -149,51 +149,53 @@ done:
cgit_print_layout_end();
}
-void cgit_print_repo_readme_no_layout(const char *path)
-{
- char *filename, *ref, *mimetype;
- int free_filename = 0;
-
- mimetype = get_mimetype_for_filename(path);
- if (mimetype && (!strncmp(mimetype, "image/", 6) || !strncmp(mimetype, "video/", 6))) {
- ctx.page.mimetype = mimetype;
- ctx.page.charset = NULL;
- cgit_print_plain();
- free(mimetype);
- return;
+// int read_tree_recursive(struct repository *r,
+// struct tree *tree,
+// const char *base, int baselen,
+// int stage, const struct pathspec *pathspec,
+// read_tree_fn_t fn, void *context);
+struct get_readme_oid_ctx {
+ const struct object_id *oid;
+ char **filename;
+};
+static int get_readme_oid_cb(const struct object_id *oid, struct strbuf *base,
+ const char *pathname, unsigned mode, int stage, void *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;
+ *(ctx->filename) = xstrdup(pathname);
+ // TODO: maybe skip by returning != 0
}
- free(mimetype);
- // cgit_print_layout_start();
- if (ctx.repo->readme.nr == 0)
- goto done;
-
- filename = ctx.repo->readme.items[0].string;
- ref = ctx.repo->readme.items[0].util;
+ return 0;
+}
+const struct object_id * get_readme_oid(const struct object_id *oid, char **filename) {
+ struct tree *tree = parse_tree_indirect(oid);
+ 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;
+}
- if (path) {
- free_filename = 1;
- filename = append_readme_path(filename, ref, path);
- if (!filename)
- goto done;
- }
+void cgit_print_repo_readme_no_layout(const struct object_id *oid)
+{
+ char *filename = NULL;
+ const struct object_id *readme_oid = get_readme_oid(oid, &filename);
+ if (readme_oid) {
+ html("<div id='summary'>");
+ cgit_open_filter(ctx.repo->about_filter, filename);
+ cgit_print_oid(readme_oid);
+ cgit_close_filter(ctx.repo->about_filter);
- /* Print the calculated readme, either from the git repo or from the
- * filesystem, while applying the about-filter.
- */
- html("<div id='summary'>");
- cgit_open_filter(ctx.repo->about_filter, filename);
- if (ref)
- cgit_print_file(filename, ref, 1);
- else
- html_include(filename);
- cgit_close_filter(ctx.repo->about_filter);
+ html("</div>");
- html("</div>");
- if (free_filename)
free(filename);
-
-
-done:
- // cgit_print_layout_end();
+ }
}