From be98295dc24492f6607cce04ba586e3897a83543 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 23 Jul 2020 19:54:13 +0000 Subject: [PATCH] feat(3p/cgit): add "this commit" option to switch form Branches are grouped into their own section to make the "this commit" option visually distinct. Adding this option will result in two options being marked as selected if a branch has the same name as a commit oid. But that would cause all sorts of other problems anyway (attempting to switch to the branch would actually give you the commit, etc.), so let's not worry about that. A "permalink" link on the blob view next to the "plain" link would probably be more discoverable, but that would only work for the blob view. The switch UI is visible everywhere. This patch is in use already at and . Signed-off-by: Alyssa Ross Message-Id: <20200723204820.16776-1-hi@alyssa.is> Cc: Profpatsch Change-Id: I7e88d1231dd402e0ad764e16b28e9a51964c6293 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1382 Tested-by: BuildkiteCI Reviewed-by: tazjin --- third_party/cgit/ui-shared.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/third_party/cgit/ui-shared.c b/third_party/cgit/ui-shared.c index af2176719..7670276f4 100644 --- a/third_party/cgit/ui-shared.c +++ b/third_party/cgit/ui-shared.c @@ -894,6 +894,15 @@ void cgit_add_clone_urls(void (*fn)(const char *)) add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); } +static int print_this_commit_option(void) +{ + struct object_id oid; + if (get_oid(ctx.qry.head, &oid)) + return 1; + html_option("this commit", oid_to_hex(&oid), ctx.qry.head); + return 0; +} + static int print_branch_option(const char *refname, const struct object_id *oid, int flags, void *cb_data) { @@ -999,9 +1008,12 @@ static void print_header(void) html("
\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html(" "); html(""); html("
");