Implement themed log page

This commit is contained in:
RunasSudo 2025-05-14 22:04:12 +10:00
parent f39308f3c8
commit d8ae2c42e6
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
9 changed files with 84 additions and 12 deletions

View File

@ -129,7 +129,7 @@ $(CGIT_PREFIX).depend:
$(CGIT_PREFIX)themed/.depend: $(CGIT_PREFIX)themed/.depend:
@mkdir -p $@ @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 $^ > $@ cd $(CGIT_PREFIX)themed; python -m htmlcc $^ > $@
$(CGIT_PREFIX)themed/themed.css: $(CGIT_PREFIX)themed/themed.in.css $(CGIT_PREFIX)themed/themed.css: $(CGIT_PREFIX)themed/themed.in.css

9
cmd.c
View File

@ -99,10 +99,11 @@ static void info_fn(void)
static void log_fn(void) static void log_fn(void)
{ {
cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, //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.qry.grep, ctx.qry.search, ctx.qry.path, 1,
ctx.repo->enable_commit_graph, // ctx.repo->enable_commit_graph,
ctx.repo->commit_sort); // ctx.repo->commit_sort);
cgit_print_log();
} }
static void ls_cache_fn(void) static void ls_cache_fn(void)

View File

@ -152,9 +152,11 @@
// Process the commit // Process the commit
num_commits++; num_commits++;
release_commit_memory(the_repository->parsed_objects, commit); // ?? This causes subsequent walks to return commits with index 0
commit->parents = NULL; //release_commit_memory(the_repository->parsed_objects, commit);
//commit->parents = NULL;
} }
reset_revision_walk();
return num_commits; return num_commits;
} }

58
themed/log.html Normal file
View File

@ -0,0 +1,58 @@
{% page cgit_print_log %}
{! page_start(); !}
{! repo_header(); !}
<main class="max-w-[1280px] mx-auto py-4">{# 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);
!}
<div class="grid grid-cols-[1fr_auto_auto] border border-gray-300 rounded-md">
{# Commits list #}
<div class="col-span-3 rounded-t-md bg-gray-50 px-3 py-2 font-semibold text-sm">
Commits
</div>
{% while (commit = get_revision(&rev)) != NULL %}
{! struct commitinfo *info = cgit_parse_commit(commit); !}
<div class="px-3 py-2 border-t border-gray-300">
<div><a href="{! cgit_shared_repolink_url_with_delimiter("commit", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&commit->object.oid) }}" class="hover:text-blue-600 hover:underline">{{ info->subject }}</a></div>
<div class="mt-2 text-sm text-gray-500 flex gap-x-1 items-center">
<img src="{! gravatar_url(info->author_email); !}?s=16">
{{ info->author }} committed {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago
</div>
</div>
<div class="px-3 py-2 border-t border-gray-300 flex items-center">
{! char short_commit_id[8]; !}
{! memcpy(short_commit_id, oid_to_hex(&commit->object.oid), 7); !}
{! short_commit_id[7] = '\0'; !}
<a href="{! cgit_shared_repolink_url_with_delimiter("commit", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&commit->object.oid) }}" class="text-sm font-mono text-gray-500 hover:text-blue-600 hover:underline">{{ short_commit_id }}</a>
</div>
<div class="px-3 py-2 border-t border-gray-300 flex items-center">
<a href="{! cgit_shared_repolink_url_with_delimiter("tree", ctx.qry.head, ctx.qry.vpath); !}id={{ oid_to_hex(&commit->object.oid) }}" class="text-gray-500 hover:text-blue-600">
{# Heroicons mini code-bracket #}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-5"><path fill-rule="evenodd" d="M6.28 5.22a.75.75 0 0 1 0 1.06L2.56 10l3.72 3.72a.75.75 0 0 1-1.06 1.06L.97 10.53a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0Zm7.44 0a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L17.44 10l-3.72-3.72a.75.75 0 0 1 0-1.06ZM11.377 2.011a.75.75 0 0 1 .612.867l-2.5 14.5a.75.75 0 0 1-1.478-.255l2.5-14.5a.75.75 0 0 1 .866-.612Z" clip-rule="evenodd" /></svg>
</a>
</div>
{! cgit_free_commitinfo(info); !}
{! release_commit_memory(the_repository->parsed_objects, commit); !}
{! commit->parents = NULL; !}
{% endwhile %}
{! reset_revision_walk(); !}
</div>
</main>
{! page_end(); !}
{% endpage %}

View File

@ -365,7 +365,7 @@ static char *next_token(char **src)
return result; 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) const char *path, int pager, int commit_graph, int commit_sort)
{ {
struct rev_info rev; struct rev_info rev;

View File

@ -1,9 +1,10 @@
#ifndef UI_LOG_H #ifndef UI_LOG_H
#define 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, char *pattern, const char *path, int pager,
int commit_graph, int commit_sort); int commit_graph, int commit_sort);
extern void cgit_print_log(void);
extern void show_commit_decorations(struct commit *commit); extern void show_commit_decorations(struct commit *commit);
#endif /* UI_LOG_H */ #endif /* UI_LOG_H */

View File

@ -318,7 +318,7 @@ static char *repolink(const char *title, const char *class, const char *page,
return fmt("%s", delim); 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 = "?"; char *delim = "?";
@ -353,6 +353,15 @@ void cgit_shared_repolink_url(const char *page, const char *head, const char *pa
html_url_arg(head); html_url_arg(head);
delim = "&amp;"; delim = "&amp;";
} }
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, static void reporevlink(const char *page, const char *name, const char *title,

View File

@ -1,7 +1,8 @@
#ifndef UI_SHARED_H #ifndef UI_SHARED_H
#define 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 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); extern const char *cgit_httpscheme(void);

View File

@ -56,7 +56,7 @@ void cgit_print_summary(void)
cgit_print_tags(ctx.cfg.summary_tags); cgit_print_tags(ctx.cfg.summary_tags);
if (ctx.cfg.summary_log > 0) { if (ctx.cfg.summary_log > 0) {
htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns); htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", 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); NULL, NULL, 0, 0, 0);
} }
urls = 0; urls = 0;