From d8ae2c42e60e355c59c61fc117c0fdc534854b28 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 14 May 2025 22:04:12 +1000 Subject: [PATCH] Implement themed log page --- cgit.mk | 2 +- cmd.c | 9 ++++---- themed/base.html | 6 +++-- themed/log.html | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ ui-log.c | 2 +- ui-log.h | 3 ++- ui-shared.c | 11 ++++++++- ui-shared.h | 3 ++- ui-summary.c | 2 +- 9 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 themed/log.html diff --git a/cgit.mk b/cgit.mk index e4a619c..822c729 100644 --- a/cgit.mk +++ b/cgit.mk @@ -129,7 +129,7 @@ $(CGIT_PREFIX).depend: $(CGIT_PREFIX)themed/.depend: @mkdir -p $@ -$(CGIT_PREFIX)themed/themed.c: $(CGIT_PREFIX)themed/base.html $(CGIT_PREFIX)themed/index.html $(CGIT_PREFIX)themed/refs.html +$(CGIT_PREFIX)themed/themed.c: $(CGIT_PREFIX)themed/base.html $(CGIT_PREFIX)themed/index.html $(CGIT_PREFIX)themed/log.html $(CGIT_PREFIX)themed/refs.html cd $(CGIT_PREFIX)themed; python -m htmlcc $^ > $@ $(CGIT_PREFIX)themed/themed.css: $(CGIT_PREFIX)themed/themed.in.css diff --git a/cmd.c b/cmd.c index 0eb75b1..7f92197 100644 --- a/cmd.c +++ b/cmd.c @@ -99,10 +99,11 @@ static void info_fn(void) static void log_fn(void) { - cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, - ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, - ctx.repo->enable_commit_graph, - ctx.repo->commit_sort); + //cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, + // ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, + // ctx.repo->enable_commit_graph, + // ctx.repo->commit_sort); + cgit_print_log(); } static void ls_cache_fn(void) diff --git a/themed/base.html b/themed/base.html index c2f1a81..5386504 100644 --- a/themed/base.html +++ b/themed/base.html @@ -152,9 +152,11 @@ // Process the commit num_commits++; - release_commit_memory(the_repository->parsed_objects, commit); - commit->parents = NULL; + // ?? This causes subsequent walks to return commits with index 0 + //release_commit_memory(the_repository->parsed_objects, commit); + //commit->parents = NULL; } + reset_revision_walk(); return num_commits; } diff --git a/themed/log.html b/themed/log.html new file mode 100644 index 0000000..4a26a53 --- /dev/null +++ b/themed/log.html @@ -0,0 +1,58 @@ +{% page cgit_print_log %} +{! page_start(); !} +{! repo_header(); !} +
{# Main content #} +{! repo_description_panel(); !} +{! repo_summary_bar(); !} + {! + struct rev_info rev; + struct commit *commit; + + const char *argv[] = {NULL, ctx.qry.head}; + int argc = 2; + + repo_init_revisions(the_repository, &rev, NULL); + rev.abbrev = DEFAULT_ABBREV; + rev.commit_format = CMIT_FMT_DEFAULT; + rev.verbose_header = 1; + rev.show_root_diff = 0; + rev.ignore_missing = 1; + rev.simplify_history = 1; + setup_revisions(argc, argv, &rev, NULL); + prepare_revision_walk(&rev); + !} +
+ {# Commits list #} +
+ Commits +
+ {% while (commit = get_revision(&rev)) != NULL %} + {! struct commitinfo *info = cgit_parse_commit(commit); !} +
+
object.oid) }}" class="hover:text-blue-600 hover:underline">{{ info->subject }}
+
+ + {{ info->author }} committed {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago +
+
+
+ {! char short_commit_id[8]; !} + {! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !} + {! short_commit_id[7] = '\0'; !} + object.oid) }}" class="text-sm font-mono text-gray-500 hover:text-blue-600 hover:underline">{{ short_commit_id }} +
+ + {! cgit_free_commitinfo(info); !} + {! release_commit_memory(the_repository->parsed_objects, commit); !} + {! commit->parents = NULL; !} + {% endwhile %} + {! reset_revision_walk(); !} +
+
+{! page_end(); !} +{% endpage %} diff --git a/ui-log.c b/ui-log.c index ee2a607..11cc539 100644 --- a/ui-log.c +++ b/ui-log.c @@ -365,7 +365,7 @@ static char *next_token(char **src) return result; } -void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, +void _orig_cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, const char *path, int pager, int commit_graph, int commit_sort) { struct rev_info rev; diff --git a/ui-log.h b/ui-log.h index 325607c..6a5706d 100644 --- a/ui-log.h +++ b/ui-log.h @@ -1,9 +1,10 @@ #ifndef UI_LOG_H #define UI_LOG_H -extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, +extern void _orig_cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, const char *path, int pager, int commit_graph, int commit_sort); +extern void cgit_print_log(void); extern void show_commit_decorations(struct commit *commit); #endif /* UI_LOG_H */ diff --git a/ui-shared.c b/ui-shared.c index 8922e7d..9d36f86 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -318,7 +318,7 @@ static char *repolink(const char *title, const char *class, const char *page, return fmt("%s", delim); } -void cgit_shared_repolink_url(const char *page, const char *head, const char *path) +const char *cgit_shared_repolink_url(const char *page, const char *head, const char *path) { char *delim = "?"; @@ -353,6 +353,15 @@ void cgit_shared_repolink_url(const char *page, const char *head, const char *pa html_url_arg(head); delim = "&"; } + + return delim; +} + +void cgit_shared_repolink_url_with_delimiter(const char *page, const char *head, const char *path) +{ + /* Print the repolink with trailing delimiter */ + const char *delim = cgit_shared_repolink_url(page, head, path); + html(delim); } static void reporevlink(const char *page, const char *name, const char *title, diff --git a/ui-shared.h b/ui-shared.h index 8f96c28..6867ce3 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -1,7 +1,8 @@ #ifndef UI_SHARED_H #define UI_SHARED_H -extern void cgit_shared_repolink_url(const char *page, const char *head, const char *path); +extern const char *cgit_shared_repolink_url(const char *page, const char *head, const char *path); +extern void cgit_shared_repolink_url_with_delimiter(const char *page, const char *head, const char *path); extern void cgit_shared_site_url(const char *page, const char *search, const char *sort, int ofs, int always_root); extern const char *cgit_httpscheme(void); diff --git a/ui-summary.c b/ui-summary.c index 947812a..b855267 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -56,7 +56,7 @@ void cgit_print_summary(void) 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, + _orig_cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, NULL, NULL, 0, 0, 0); } urls = 0;