about summary refs log tree commit diff stats
path: root/ui-shared.c
diff options
context:
space:
mode:
authorAlyssa Ross2020-07-23 20:48:21 +0000
committerJune McEnroe2022-02-13 11:52:37 -0500
commit6524fe67102d55dd4f67581117366fc89ad469c2 (patch)
tree289286d1f0d659d5b2ffce08ca55a84855c861e9 /ui-shared.c
parentShow subject in commit page title (diff)
downloadcgit-6524fe67102d55dd4f67581117366fc89ad469c2.tar.gz
cgit-6524fe67102d55dd4f67581117366fc89ad469c2.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>
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index a295102..dd312bb 100644 --- a/ui-shared.c +++ b/ui-shared.c
@@ -893,6 +893,15 @@ void cgit_add_clone_urls(void (*fn)(const char *))
893 add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); 893 add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url);
894} 894}
895 895
896static int print_this_commit_option(void)
897{
898 struct object_id oid;
899 if (get_oid(ctx.qry.head, &oid))
900 return 1;
901 html_option(oid_to_hex(&oid), "this commit", ctx.qry.head);
902 return 0;
903}
904
896static int print_branch_option(const char *refname, const struct object_id *oid, 905static int print_branch_option(const char *refname, const struct object_id *oid,
897 int flags, void *cb_data) 906 int flags, void *cb_data)
898{ 907{
@@ -1000,9 +1009,12 @@ static void print_header(void)
1000 html("<form method='get'>\n"); 1009 html("<form method='get'>\n");
1001 cgit_add_hidden_formfields(0, 1, ctx.qry.page); 1010 cgit_add_hidden_formfields(0, 1, ctx.qry.page);
1002 html("<select name='h' onchange='this.form.submit();'>\n"); 1011 html("<select name='h' onchange='this.form.submit();'>\n");
1012 print_this_commit_option();
1013 html("<optgroup label='branches'>");
1003 for_each_branch_ref(print_branch_option, ctx.qry.head); 1014 for_each_branch_ref(print_branch_option, ctx.qry.head);
1004 if (ctx.repo->enable_remote_branches) 1015 if (ctx.repo->enable_remote_branches)
1005 for_each_remote_ref(print_branch_option, ctx.qry.head); 1016 for_each_remote_ref(print_branch_option, ctx.qry.head);
1017 html("</optgroup>");
1006 html("</select> "); 1018 html("</select> ");
1007 html("<input type='submit' value='switch'/>"); 1019 html("<input type='submit' value='switch'/>");
1008 html("</form>"); 1020 html("</form>");