aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2026-05-21 14:17:50 +0200
committerChristian Hesse <mail@eworm.de>2026-11-10 20:16:57 +0100
commitea0cfea5e81c2950fa3a83cef22c491b1ffb7a33 (patch)
tree4bed04ab5d8c1b7ecdd7d61abecb6e1f314c4eb0
parentef4b8eeb5948e70218524a8b464173597cfca051 (diff)
downloadcgit-ea0cfea5e81c2950fa3a83cef22c491b1ffb7a33.tar.gz
cgit-ea0cfea5e81c2950fa3a83cef22c491b1ffb7a33.tar.bz2
cgit-ea0cfea5e81c2950fa3a83cef22c491b1ffb7a33.zip
ui-shared: add "this commit" option to switch formch/for-jason
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. Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r--ui-shared.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 9e49a80..9126aea 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -947,6 +947,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 (repo_get_oid(the_repository, ctx.qry.head, &oid))
+ return 1;
+ html_option(oid_to_hex(&oid), "this commit", ctx.qry.head);
+ return 0;
+}
+
static int print_branch_option(const struct reference *ref, void *cb_data)
{
char *name = (char *)ref->name;
@@ -1053,11 +1062,14 @@ static void print_header(void)
html("<form method='get'>\n");
cgit_add_hidden_formfields(0, 1, ctx.qry.page);
html("<select name='h' onchange='this.form.submit();'>\n");
+ print_this_commit_option();
+ html("<optgroup label='branches'>");
refs_for_each_branch_ref(get_main_ref_store(the_repository),
print_branch_option, ctx.qry.head);
if (ctx.repo->enable_remote_branches)
refs_for_each_remote_ref(get_main_ref_store(the_repository),
print_branch_option, ctx.qry.head);
+ html("</optgroup>");
html("</select> ");
html("<input type='submit' value='switch'/>");
html("</form>");