From e8948e814f3632d8100dfc7b1a27b4dfad2cf7bb Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:16:01 -0700 Subject: Drop the thunks that only forward to a renderer --- source/cmd.c | 50 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) (limited to 'source/cmd.c') diff --git a/source/cmd.c b/source/cmd.c index 22a6c19..676e144 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -1,8 +1,8 @@ /* - * One thunk per page, each pulling the parts of the request its renderer - * needs out of the global ctx, plus the table that maps a page name onto its - * thunk. Keeping the thunks here lets every renderer take ordinary arguments - * instead of reaching into the request state itself. + * A renderer that reads the request itself goes into the page table as it is. + * The others sit behind a thunk here that pulls their arguments out of the + * global ctx or does some work first, such as checking that the page is + * enabled. */ #include "cache.h" @@ -27,11 +27,6 @@ #include "ui-tag.h" #include "ui-tree.h" -static void head_fn(void) -{ - cgit_clone_head(); -} - static void about_fn(void) { char *query, *summary; @@ -89,11 +84,6 @@ static void diff_fn(void) cgit_print_diff(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path, 1, 0); } -static void info_fn(void) -{ - cgit_clone_info(); -} - static void log_fn(void) { cgit_prefix_title("log"); @@ -122,21 +112,11 @@ static void ls_cache_fn(void) cache_ls(ctx.cfg.cache_root); } -static void objects_fn(void) -{ - cgit_clone_objects(); -} - static void patch_fn(void) { cgit_print_patch(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path); } -static void plain_fn(void) -{ - cgit_print_plain(); -} - static void rawdiff_fn(void) { cgit_print_diff(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path, 1, 1); @@ -148,11 +128,6 @@ static void refs_fn(void) cgit_print_refs(); } -static void repolist_fn(void) -{ - cgit_print_repolist(); -} - static void snapshot_fn(void) { cgit_print_snapshot(ctx.qry.head, ctx.qry.oid, ctx.qry.path, ctx.qry.nohead); @@ -168,11 +143,6 @@ static void stats_fn(void) } } -static void summary_fn(void) -{ - cgit_print_summary(); -} - static void tag_fn(void) { cgit_print_tag(ctx.qry.oid); @@ -186,25 +156,25 @@ static void tree_fn(void) // The name is what a request spells as p=, so these strings are part of the // URL space and cannot be renamed. static const struct cgit_cmd commands[] = { - { .name = "HEAD", .fn = head_fn, .want_repo = 1, .is_clone = 1 }, + { .name = "HEAD", .fn = cgit_clone_head, .want_repo = 1, .is_clone = 1 }, { .name = "about", .fn = about_fn }, { .name = "atom", .fn = atom_fn, .want_repo = 1 }, { .name = "blame", .fn = blame_fn, .want_repo = 1, .want_vpath = 1 }, { .name = "blob", .fn = blob_fn, .want_repo = 1 }, { .name = "commit", .fn = commit_fn, .want_repo = 1, .want_vpath = 1 }, { .name = "diff", .fn = diff_fn, .want_repo = 1, .want_vpath = 1 }, - { .name = "info", .fn = info_fn, .want_repo = 1, .is_clone = 1 }, + { .name = "info", .fn = cgit_clone_info, .want_repo = 1, .is_clone = 1 }, { .name = "log", .fn = log_fn, .want_repo = 1, .want_vpath = 1 }, { .name = "ls_cache", .fn = ls_cache_fn }, - { .name = "objects", .fn = objects_fn, .want_repo = 1, .is_clone = 1 }, + { .name = "objects", .fn = cgit_clone_objects, .want_repo = 1, .is_clone = 1 }, { .name = "patch", .fn = patch_fn, .want_repo = 1, .want_vpath = 1 }, - { .name = "plain", .fn = plain_fn, .want_repo = 1 }, + { .name = "plain", .fn = cgit_print_plain, .want_repo = 1 }, { .name = "rawdiff", .fn = rawdiff_fn, .want_repo = 1, .want_vpath = 1 }, { .name = "refs", .fn = refs_fn, .want_repo = 1 }, - { .name = "repolist", .fn = repolist_fn }, + { .name = "repolist", .fn = cgit_print_repolist }, { .name = "snapshot", .fn = snapshot_fn, .want_repo = 1 }, { .name = "stats", .fn = stats_fn, .want_repo = 1, .want_vpath = 1 }, - { .name = "summary", .fn = summary_fn, .want_repo = 1 }, + { .name = "summary", .fn = cgit_print_summary, .want_repo = 1 }, { .name = "tag", .fn = tag_fn, .want_repo = 1 }, { .name = "tree", .fn = tree_fn, .want_repo = 1, .want_vpath = 1 }, }; -- cgit