about summary refs log tree commit diff
path: root/web/cgit-taz
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-20T20·18+0000
committerVincent Ambo <tazjin@google.com>2019-12-20T20·18+0000
commit03bfe08e1dd9faf48b06cb146bfa446575cde88a (patch)
tree55317968922a9b2a01516f1b79527874df037517 /web/cgit-taz
parente52eed3cd4f73779c2e7c350537fb346835ba9f3 (diff)
chore: Significantly restructure folder layout r/237
This moves the various projects from "type-based" folders (such as
"services" or "tools") into more appropriate semantic folders (such as
"nix", "ops" or "web").

Deprecated projects (nixcon-demo & gotest) which only existed for
testing/demonstration purposes have been removed.

(Note: *all* builds are broken with this commit)
Diffstat (limited to 'web/cgit-taz')
-rw-r--r--web/cgit-taz/cgit_depot_url.patch97
-rw-r--r--web/cgit-taz/cgit_idx.patch13
-rw-r--r--web/cgit-taz/default.nix69
3 files changed, 179 insertions, 0 deletions
diff --git a/web/cgit-taz/cgit_depot_url.patch b/web/cgit-taz/cgit_depot_url.patch
new file mode 100644
index 0000000000..cb81a2a49a
--- /dev/null
+++ b/web/cgit-taz/cgit_depot_url.patch
@@ -0,0 +1,97 @@
+diff --git a/cmd.c b/cmd.c
+index 63f0ae5..b37b79d 100644
+--- a/cmd.c
++++ b/cmd.c
+@@ -39,29 +39,7 @@ static void atom_fn(void)
+ 
+ static void about_fn(void)
+ {
+-	if (ctx.repo) {
+-		size_t path_info_len = ctx.env.path_info ? strlen(ctx.env.path_info) : 0;
+-		if (!ctx.qry.path &&
+-		    ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' &&
+-		    (!path_info_len || ctx.env.path_info[path_info_len - 1] != '/')) {
+-			char *currenturl = cgit_currenturl();
+-			char *redirect = fmtalloc("%s/", currenturl);
+-			cgit_redirect(redirect, true);
+-			free(currenturl);
+-			free(redirect);
+-		} else if (ctx.repo->readme.nr)
+-			cgit_print_repo_readme(ctx.qry.path);
+-		else if (ctx.repo->homepage)
+-			cgit_redirect(ctx.repo->homepage, false);
+-		else {
+-			char *currenturl = cgit_currenturl();
+-			char *redirect = fmtalloc("%s../", currenturl);
+-			cgit_redirect(redirect, false);
+-			free(currenturl);
+-			free(redirect);
+-		}
+-	} else
+-		cgit_print_site_readme();
++	cgit_print_repo_readme(ctx.qry.path);
+ }
+ 
+ static void blame_fn(void)
+diff --git a/ui-shared.c b/ui-shared.c
+index 739505a..c7c3754 100644
+--- a/ui-shared.c
++++ b/ui-shared.c
+@@ -95,29 +95,23 @@ const char *cgit_loginurl(void)
+ 
+ char *cgit_repourl(const char *reponame)
+ {
+-	if (ctx.cfg.virtual_root)
+-		return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame);
+-	else
+-		return fmtalloc("?r=%s", reponame);
++	// my cgit instance *only* serves the depot, hence that's the only value ever
++	// needed.
++	return fmtalloc("/");
+ }
+ 
+ char *cgit_fileurl(const char *reponame, const char *pagename,
+ 		   const char *filename, const char *query)
+ {
+ 	struct strbuf sb = STRBUF_INIT;
+-	char *delim;
+ 
+-	if (ctx.cfg.virtual_root) {
+-		strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame,
+-			    pagename, (filename ? filename:""));
+-		delim = "?";
+-	} else {
+-		strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename,
+-			    (filename ? filename : ""));
+-		delim = "&amp;";
++	strbuf_addf(&sb, "%s%s/%s", ctx.cfg.virtual_root,
++		pagename, (filename ? filename:""));
++
++	if (query) {
++		strbuf_addf(&sb, "%s%s", "?", query);
+ 	}
+-	if (query)
+-		strbuf_addf(&sb, "%s%s", delim, query);
++
+ 	return strbuf_detach(&sb, NULL);
+ }
+ 
+@@ -245,9 +239,6 @@ static char *repolink(const char *title, const char *class, const char *page,
+ 	html(" href='");
+ 	if (ctx.cfg.virtual_root) {
+ 		html_url_path(ctx.cfg.virtual_root);
+-		html_url_path(ctx.repo->url);
+-		if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
+-			html("/");
+ 		if (page) {
+ 			html_url_path(page);
+ 			html("/");
+@@ -957,8 +948,6 @@ static void print_header(void)
+ 
+ 	html("<td class='main'>");
+ 	if (ctx.repo) {
+-		cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
+-		html(" : ");
+ 		cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
+ 		if (ctx.env.authenticated) {
+ 			html("</td><td class='form'>");
diff --git a/web/cgit-taz/cgit_idx.patch b/web/cgit-taz/cgit_idx.patch
new file mode 100644
index 0000000000..67dbc0c7ab
--- /dev/null
+++ b/web/cgit-taz/cgit_idx.patch
@@ -0,0 +1,13 @@
+diff --git a/config.h b/config.h
+index 65ab1e3..cde470f 100644
+--- a/config.h
++++ b/config.h
+@@ -327,7 +327,7 @@
+ /* CONFIGURE: A list of index filenames to check.  The files are searched
+ ** for in this order.
+ */
+-#define INDEX_NAMES "index.html", "index.htm", "index.xhtml", "index.xht", "Default.htm", "index.cgi"
++#define INDEX_NAMES "cgit.cgi"
+ 
+ /* CONFIGURE: If this is defined then thttpd will automatically generate
+ ** index pages for directories that don't have an explicit index file.
diff --git a/web/cgit-taz/default.nix b/web/cgit-taz/default.nix
new file mode 100644
index 0000000000..4559eb4dbf
--- /dev/null
+++ b/web/cgit-taz/default.nix
@@ -0,0 +1,69 @@
+# This derivation configures a 'cgit' instance to serve repositories
+# from a different source.
+#
+# In the first round this will just serve my GitHub repositories until
+# I'm happy with the display.
+
+{ pkgs, ... }:
+
+with pkgs.third_party;
+
+let
+  # Patched version of cgit that builds repository URLs correctly
+  # (since only one repository is served)
+  monocgit = cgit.overrideAttrs(old: {
+    patches = old.patches ++ [ ./cgit_depot_url.patch ];
+  });
+
+  cgitConfig = writeText "cgitrc" ''
+    # Global configuration
+    virtual-root=/
+    enable-http-clone=1
+    readme=:README.md
+    about-filter=${monocgit}/lib/cgit/filters/about-formatting.sh
+    source-filter=${monocgit}/lib//cgit/filters/syntax-highlighting.py
+
+    # Repository configuration
+    repo.url=depot
+    repo.path=/git/depot/.git
+    repo.desc=tazjin's personal monorepo
+    repo.owner=tazjin <mail@tazj.in>
+    repo.clone-url=https://git.tazj.in ssh://source.developers.google.com:2022/p/tazjins-infrastructure/r/depot
+    repo.enable-remote-branches=1
+  '';
+
+  thttpdConfig = writeText "thttpd.conf" ''
+    port=8080
+    dir=${monocgit}/cgit
+    nochroot
+    novhost
+    logfile=/dev/stdout
+    cgipat=**.cgi
+  '';
+
+  # Patched version of thttpd that serves cgit.cgi as the index and
+  # sets the environment variable for pointing cgit at the correct
+  # configuration.
+  #
+  # Things are done this way because recompilation of thttpd is much
+  # faster than cgit and I don't want to wait long when iterating on
+  # config.
+  thttpdConfigPatch = writeText "thttpd_cgit_conf.patch" ''
+    diff --git a/libhttpd.c b/libhttpd.c
+    index c6b1622..eef4b73 100644
+    --- a/libhttpd.c
+    +++ b/libhttpd.c
+    @@ -3055,4 +3055,6 @@ make_envp( httpd_conn* hc )
+
+         envn = 0;
+    +    // force cgit to load the correct configuration
+    +    envp[envn++] = "CGIT_CONFIG=${cgitConfig}";
+         envp[envn++] = build_env( "PATH=%s", CGI_PATH );
+     #ifdef CGI_LD_LIBRARY_PATH
+  '';
+  thttpdCgit = thttpd.overrideAttrs(old: {
+    patches = [ ./cgit_idx.patch thttpdConfigPatch ];
+  });
+in writeShellScriptBin "cgit-launch" ''
+  exec ${thttpdCgit}/bin/thttpd -D -C ${thttpdConfig}
+# ''