summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-07-23 20:48:21 +0000
committerJune McEnroe <june@causal.agency>2020-12-27 19:59:50 -0500
commitdb652695744cc54584296b54289166b4b21ac407 (patch)
tree01da6abc22f1b45bb8f1aed64b6b956aee667453
parentShow subject in commit page title (diff)
downloadsrc-db652695744cc54584296b54289166b4b21ac407.tar.gz
src-db652695744cc54584296b54289166b4b21ac407.zip
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.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rw-r--r--www/git.causal.agency/cgit/ui-shared.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/www/git.causal.agency/cgit/ui-shared.c b/www/git.causal.agency/cgit/ui-shared.c
index a2951023..dd312bb0 100644
--- a/www/git.causal.agency/cgit/ui-shared.c
+++ b/www/git.causal.agency/cgit/ui-shared.c
@@ -893,6 +893,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(oid_to_hex(&oid), "this commit", ctx.qry.head);
+	return 0;
+}
+
 static int print_branch_option(const char *refname, const struct object_id *oid,
 			       int flags, void *cb_data)
 {
@@ -1000,9 +1009,12 @@ 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'>");
 			for_each_branch_ref(print_branch_option, ctx.qry.head);
 			if (ctx.repo->enable_remote_branches)
 				for_each_remote_ref(print_branch_option, ctx.qry.head);
+			html("</optgroup>");
 			html("</select> ");
 			html("<input type='submit' value='switch'/>");
 			html("</form>");