From 3e40b846456e4efc06ece7180ef152e053114385 Mon Sep 17 00:00:00 2001 From: Saya Andy Date: Tue, 8 Sep 2026 00:11:57 +0700 Subject: diff: allow stepping back N commits from the selected refs The ref pickers can only select the exact ref that is shown. Add an offset input next to each picker (idoff and id2off), whose value is the number of commits to step back, so any ancestor of a branch or tag can be compared without typing a rev into the url by hand. An apply button submits the values typed there, since text inputs cannot be auto-submitted on their own; the flip link swaps the offsets along with the refs, and the file-level links carry them through. By default both offsets are empty, meaning the selected refs themselves. An empty ref submitted from the form is likewise treated as no ref instead of triggering a bad object name error. --- ui-shared.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 686fde0..9eb48a9 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -494,6 +494,21 @@ void cgit_diff_link(const char *name, const char *title, const char *class, html_url_arg(old_rev); delim = "&"; } + /* + * Emit the ref offsets after the refs so that they follow the + * refs through file-level links; a zero offset means the ref + * itself. + */ + if (ctx.qry.idoff) { + html(delim); + htmlf("idoff=%d", ctx.qry.idoff); + delim = "&"; + } + if (ctx.qry.id2off) { + html(delim); + htmlf("id2off=%d", ctx.qry.id2off); + delim = "&"; + } if (ctx.qry.difftype) { html(delim); htmlf("dt=%d", ctx.qry.difftype); @@ -1051,6 +1066,10 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, html_hidden("id", ctx.qry.oid); if (ctx.qry.oid2) html_hidden("id2", ctx.qry.oid2); + if (ctx.qry.idoff) + html_hidden("idoff", fmt("%d", ctx.qry.idoff)); + if (ctx.qry.id2off) + html_hidden("id2off", fmt("%d", ctx.qry.id2off)); if (ctx.qry.showmsg) html_hidden("showmsg", "1"); -- cgit v1.3.1+17