about summary refs log tree commit diff
path: root/overlays
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-07-23 20:34:26 +0000
committerAlyssa Ross <hi@alyssa.is>2020-08-15 07:58:18 +0000
commita4cec65468271e55cb603f37118b428d68aca9fd (patch)
tree07de718babae134e99ba955692466c61380d0e0b /overlays
parent5e6680590e8c540c7127cb8d8b7b611418fb2911 (diff)
downloadnixlib-a4cec65468271e55cb603f37118b428d68aca9fd.tar
nixlib-a4cec65468271e55cb603f37118b428d68aca9fd.tar.gz
nixlib-a4cec65468271e55cb603f37118b428d68aca9fd.tar.bz2
nixlib-a4cec65468271e55cb603f37118b428d68aca9fd.tar.lz
nixlib-a4cec65468271e55cb603f37118b428d68aca9fd.tar.xz
nixlib-a4cec65468271e55cb603f37118b428d68aca9fd.tar.zst
nixlib-a4cec65468271e55cb603f37118b428d68aca9fd.zip
patches/cgit: add "this commit" to branch switcher
Diffstat (limited to 'overlays')
-rw-r--r--overlays/patches/cgit/default.nix1
-rw-r--r--overlays/patches/cgit/ui-shared-add-this-commit-option-to-switch-form.patch57
2 files changed, 58 insertions, 0 deletions
diff --git a/overlays/patches/cgit/default.nix b/overlays/patches/cgit/default.nix
index 816452cb2bf5..c570abe448f0 100644
--- a/overlays/patches/cgit/default.nix
+++ b/overlays/patches/cgit/default.nix
@@ -3,6 +3,7 @@
 cgit.overrideAttrs ({ patches ? [], ... }: {
   patches = patches ++ [
     ./ui-commit-use-Git-raw-note-format.patch
+    ./ui-shared-add-this-commit-option-to-switch-form.patch
     (fetchpatch {
       url = "https://git.causal.agency/cgit/patch/?id=e65d3eb446294520e2aee50966e5070661d09671";
       sha256 = "0wvckndjmxar3vgqdc3jdnpzy0xgrdlqgfaasixl3x87sdnf4kg7";
diff --git a/overlays/patches/cgit/ui-shared-add-this-commit-option-to-switch-form.patch b/overlays/patches/cgit/ui-shared-add-this-commit-option-to-switch-form.patch
new file mode 100644
index 000000000000..79ea36e4b8ce
--- /dev/null
+++ b/overlays/patches/cgit/ui-shared-add-this-commit-option-to-switch-form.patch
@@ -0,0 +1,57 @@
+From 5a682008b4b46f762d96725e69e6e1473cd7102e Mon Sep 17 00:00:00 2001
+From: Alyssa Ross <hi@alyssa.is>
+Date: Thu, 23 Jul 2020 19:54:13 +0000
+Subject: [PATCH] ui-shared: 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.
+---
+ ui-shared.c | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/ui-shared.c b/ui-shared.c
+index d2358f2..e1a3603 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, 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>");
+-- 
+2.27.0
+