From 63aa2ecd4e72800c11b08e4fb94234a117ece029 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 27 Sep 2026 22:04:58 +0300 Subject: ui-summary: (THEME) Rework what is shown in summary page Now clone and branches are shown next to commits and tags, branches only show name and age, clone does not create links, and file listing (alongside readme) is shown below --- ui-refs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ui-refs.h | 1 + ui-summary.c | 26 ++++++++++++++------------ ui-tree.c | 41 +++++++++++++++++++++++++++++++++++++++++ ui-tree.h | 1 + 5 files changed, 103 insertions(+), 12 deletions(-) diff --git a/ui-refs.c b/ui-refs.c index 11fb9fc..455f09c 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -179,6 +179,52 @@ void cgit_print_branches(int maxcount) cgit_free_reflist_inner(&list); } +void cgit_print_branches_component(int maxcount) +{ + struct reflist list; + int i; + struct commitinfo *info; + char *name; + + html("Branch" + "Age\n"); + + list.refs = NULL; + list.alloc = list.count = 0; + refs_for_each_branch_ref(get_main_ref_store(the_repository), + cgit_refs_cb, &list); + if (ctx.repo->enable_remote_branches) + refs_for_each_remote_ref(get_main_ref_store(the_repository), + cgit_refs_cb, &list); + + if (maxcount == 0 || maxcount > list.count) + maxcount = list.count; + + qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); + if (ctx.repo->branch_sort == 0) + qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); + + for (i = 0; i < maxcount; i++) { + info = list.refs[i]->commit; + name = (char *)list.refs[i]->refname; + + if (!info || list.refs[i]->object->type != OBJ_COMMIT) + continue; + + html(""); + cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, + ctx.qry.showmsg, 0); + html(""); + cgit_print_age(info->committer_date, info->committer_tz, -1); + html("\n"); + } + + if (maxcount < list.count) + print_refs_link("heads"); + + cgit_free_reflist_inner(&list); +} + void cgit_print_tags(int maxcount) { struct reflist list; diff --git a/ui-refs.h b/ui-refs.h index 1d4a54a..b9ac86a 100644 --- a/ui-refs.h +++ b/ui-refs.h @@ -2,6 +2,7 @@ #define UI_REFS_H extern void cgit_print_branches(int maxcount); +extern void cgit_print_branches_component(int maxcount); extern void cgit_print_tags(int maxcount); extern void cgit_print_refs(void); diff --git a/ui-summary.c b/ui-summary.c index 77f4c48..199364d 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -14,12 +14,13 @@ #include "ui-plain.h" #include "ui-refs.h" #include "ui-shared.h" +#include "ui-tree.h" static int urls; static void print_url(const char *url) { - int columns = 3; + int columns = 2; if (ctx.repo->enable_log_filecount) columns++; @@ -27,17 +28,12 @@ static void print_url(const char *url) columns++; if (urls++ == 0) { - htmlf(" ", columns); htmlf("Clone\n", columns); } - htmlf(""); + htmlf("", columns, url); html_txt(url); - html("\n"); + html("\n"); } void cgit_print_summary(void) @@ -50,18 +46,24 @@ void cgit_print_summary(void) columns++; cgit_print_layout_start(); + html("
"); html(""); - cgit_print_branches(ctx.cfg.summary_branches); - htmlf("", columns); - cgit_print_tags(ctx.cfg.summary_tags); if (ctx.cfg.summary_log > 0) { - htmlf("", columns); cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, NULL, NULL, 0, 0, 0); + htmlf("", columns); } + cgit_print_tags(ctx.cfg.summary_tags); urls = 0; + html("
 
 
 
"); + html("
 "); + html(""); cgit_add_clone_urls(print_url); + htmlf("", columns); + cgit_print_branches_component(ctx.cfg.summary_branches); html("
 
"); + html("
"); + cgit_print_tree_component(ctx.qry.oid, ctx.qry.path); cgit_print_layout_end(); } diff --git a/ui-tree.c b/ui-tree.c index 27cbd46..9616e33 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -431,3 +431,44 @@ void cgit_print_tree(const char *rev, char *path) cleanup: free(walk_tree_ctx.curr_rev); } + +void cgit_print_tree_component(const char *rev, char *path) +{ + struct object_id oid; + struct commit *commit; + struct walk_tree_context walk_tree_ctx = { + .match_path = path, + .state = 0 + }; + struct tree *tree; + struct pathspec paths = { + .nr = 0 + }; + + if (!rev) + rev = ctx.qry.head; + + if (path != NULL || repo_get_oid(the_repository, rev, &oid)) + return; + + commit = lookup_commit_reference(the_repository, &oid); + if (!commit || repo_parse_commit(the_repository, commit)) + return; + + walk_tree_ctx.curr_rev = xstrdup(rev); + + tree = parse_tree_indirect(get_commit_tree_oid(commit)); + if (tree) { + html("\n"); + html(""); + html(""); + html(""); + html("\n"); + read_tree(the_repository, tree, &paths, ls_item, &walk_tree_ctx); + html("
NameSize"); + html("
\n"); + cgit_print_repo_readme_component(ctx.qry.path); + } + + free(walk_tree_ctx.curr_rev); +} diff --git a/ui-tree.h b/ui-tree.h index bbd34e3..0b3488c 100644 --- a/ui-tree.h +++ b/ui-tree.h @@ -2,5 +2,6 @@ #define UI_TREE_H extern void cgit_print_tree(const char *rev, char *path); +extern void cgit_print_tree_component(const char *rev, char *path); #endif /* UI_TREE_H */ -- cgit v1.3.1-23-gd82d