List for cgit developers and users
 help / color / mirror / Atom feed
From: Alyssa Ross <>
Subject: [PATCH v2] ui-shared: add "this commit" option to switch form
Date: Thu, 23 Jul 2020 21:07:44 +0000
Message-ID: <> (raw)
In-Reply-To: <>

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

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 <>
The first version of this patch had the parameters to html_option the
wrong way round.

 ui-shared.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/ui-shared.c b/ui-shared.c
index d2358f2..812a099 100644
--- a/ui-shared.c
+++ b/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,;
 			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'/>");

      reply	other threads:[~2020-07-23 21:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23 20:48 [PATCH] " Alyssa Ross
2020-07-23 21:07 ` Alyssa Ross [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

List for cgit developers and users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 cgit cgit/ \
	public-inbox-index cgit

Example config snippet for mirrors.
Newsgroup available over NNTP:

AGPL code for this site: git clone