From e1b24b557d00407fb96755c34a8956afff56a51a Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 26 Sep 2026 08:38:40 -1000 Subject: Add stable markup hooks for site themes --- source/ui-diff.c | 71 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'source/ui-diff.c') diff --git a/source/ui-diff.c b/source/ui-diff.c index f258e9f..5c9cd1c 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -234,6 +234,13 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, u int subproject; subproject = (S_ISGITLINK(old_mode) || S_ISGITLINK(new_mode)); + // The side by side view opens its file group before the header row, + // so only the unified view opens one here. + if (!use_ssdiff) { + html("
"); + } html("
"); html("diff --git a/"); html_txt(old_path); @@ -281,6 +288,20 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, u html("
"); } +/* + * Closes the group print_file_header or cgit_ssdiff_header_begin opened. The + * side by side footer closes its own, so the unified view is the only one with + * work to do here. + */ +static void end_file(void) +{ + // The unified table keeps its whitespace, so no newline follows. + if (use_ssdiff) + cgit_ssdiff_footer(); + else + html("
"); +} + /* * The length passed counts the terminator, because a renderer strips the last * byte of every line it is given. @@ -315,12 +336,11 @@ static void print_truncated(const char *path) cgit_diff_link("View it on its own page", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, path); html("."); - if (use_ssdiff) { + if (use_ssdiff) html(""); - cgit_ssdiff_footer(); - } else { + else html(""); - } + end_file(); } static struct fileinfo *reserve_item(void) @@ -353,7 +373,7 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, int html_capture_begin(body); if (use_ssdiff) - cgit_ssdiff_header_begin(); + cgit_ssdiff_header_begin(pair->two->path); print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, &pair->two->oid, pair->two->path, pair->two->mode); if (use_ssdiff) @@ -383,8 +403,7 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, int if (*binary) print_binary_differs(); } - if (use_ssdiff) - cgit_ssdiff_footer(); + end_file(); if (render_suppressed) { // Setting the length back would keep the grown allocation, @@ -491,7 +510,7 @@ static void filepair_cb(struct diff_filepair *pair) idx = item_idx++; current_filepair = pair; if (use_ssdiff) { - cgit_ssdiff_header_begin(); + cgit_ssdiff_header_begin(pair->two->path); line_fn = cgit_ssdiff_line_cb; } print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, @@ -505,8 +524,7 @@ static void filepair_cb(struct diff_filepair *pair) } if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { print_subproject_lines(pair, line_fn); - if (use_ssdiff) - cgit_ssdiff_footer(); + end_file(); return; } if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, @@ -514,8 +532,7 @@ static void filepair_cb(struct diff_filepair *pair) cgit_print_error("Error running diff"); if (binary) print_binary_differs(); - if (use_ssdiff) - cgit_ssdiff_footer(); + end_file(); } static void print_raw_patch(const struct object_id *old_tree_oid, const struct object_id *new_tree_oid) @@ -553,14 +570,11 @@ void cgit_print_diff_ctrls(void) html("
\n"); html("diff options"); - html("
"); + html(""); cgit_add_hidden_formfields(1, 0, ctx.qry.page); - html(""); - html(""); - html(""); - html(""); - html(""); - html(""); - html(""); - html(""); - html(""); - html(""); - html(""); - html("
context:"); - html(""); selected = ctx.qry.context; if (!selected) selected = DEFAULT_DIFF_CONTEXT; @@ -569,27 +583,20 @@ void cgit_print_diff_ctrls(void) for (i = 15; i <= MAX_DIFF_CONTEXT_LINES; i += 5) html_intoption(i, cgit_fmt("%d", i), selected); html(""); - html("
space:"); - html(""); html_intoption(0, "include", ctx.qry.ignorews); html_intoption(1, "ignore", ctx.qry.ignorews); html(""); - html("
mode:"); - html(""); selected = ctx.qry.has_difftype ? ctx.qry.difftype : ctx.cfg.difftype; html_intoption(0, "unified", selected); html_intoption(1, "ssdiff", selected); html_intoption(2, "stat only", selected); - html("
"); + html(""); html(""); - html("
"); + html("
"); html("\n"); html("\n"); } -- cgit v2.8.0