From 9ad47965387c63e287afac86c498566e37265248 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 21 Dec 2019 23:36:02 +0000 Subject: feat(cgit-taz): Add patches for subtree about/ handling 1. Generate links to subtree about pages. 2. Render README files in subtrees, too. --- web/cgit-taz/0001-cgit_monorepo_urls.patch | 114 +++++++++++++++++++++++ web/cgit-taz/0002-cgit_subtree_readmes.patch | 46 +++++++++ web/cgit-taz/0003-cgit_subtree_about_links.patch | 50 ++++++++++ web/cgit-taz/cgit_depot_url.patch | 97 ------------------- web/cgit-taz/cgit_idx.patch | 13 --- web/cgit-taz/default.nix | 14 ++- web/cgit-taz/thttpd_cgi_idx.patch | 13 +++ 7 files changed, 233 insertions(+), 114 deletions(-) create mode 100644 web/cgit-taz/0001-cgit_monorepo_urls.patch create mode 100644 web/cgit-taz/0002-cgit_subtree_readmes.patch create mode 100644 web/cgit-taz/0003-cgit_subtree_about_links.patch delete mode 100644 web/cgit-taz/cgit_depot_url.patch delete mode 100644 web/cgit-taz/cgit_idx.patch create mode 100644 web/cgit-taz/thttpd_cgi_idx.patch (limited to 'web') diff --git a/web/cgit-taz/0001-cgit_monorepo_urls.patch b/web/cgit-taz/0001-cgit_monorepo_urls.patch new file mode 100644 index 0000000000..624a74b5db --- /dev/null +++ b/web/cgit-taz/0001-cgit_monorepo_urls.patch @@ -0,0 +1,114 @@ +From f6646e5a6da29da979d6954feba9d85556bc6936 Mon Sep 17 00:00:00 2001 +From: Vincent Ambo +Date: Sat, 21 Dec 2019 18:41:45 +0000 +Subject: [PATCH 1/3] feat: Generate monorepo compatible URLs + +Generates URLs that do not include the repository name. + +On git.tazj.in, only one repository (depot) is served - hence URLs +generated by cgit need not include the name. +--- + cmd.c | 24 +----------------------- + ui-shared.c | 29 +++++++++-------------------- + 2 files changed, 10 insertions(+), 43 deletions(-) + +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 = "&"; ++ 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(""); + 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(""); +-- +2.24.1.735.g03f4e72817-goog + diff --git a/web/cgit-taz/0002-cgit_subtree_readmes.patch b/web/cgit-taz/0002-cgit_subtree_readmes.patch new file mode 100644 index 0000000000..f3aba10215 --- /dev/null +++ b/web/cgit-taz/0002-cgit_subtree_readmes.patch @@ -0,0 +1,46 @@ +From 61500898c7d1363f88b763c7778cf1a8dfd13aca Mon Sep 17 00:00:00 2001 +From: Vincent Ambo +Date: Sat, 21 Dec 2019 22:58:19 +0000 +Subject: [PATCH 2/3] feat(ui-summary): Attempt to use README at each subtree + +This means that individual subtrees of a repository will also have +their READMEs rendered on the about page, for example: + + /foo/bar/README.md + +Will render on: + + /about/foo/bar/ + +This is useful for monorepo setups in which subtrees represent +individual projects. +--- + ui-summary.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/ui-summary.c b/ui-summary.c +index 8e81ac4..34ce4e9 100644 +--- a/ui-summary.c ++++ b/ui-summary.c +@@ -128,6 +128,18 @@ void cgit_print_repo_readme(char *path) + goto done; + } + ++ /* Determine which file to serve by checking whether the given filename is ++ * already a valid file and otherwise appending the expected file name of ++ * the readme. ++ * ++ * If neither yield a valid file, the user gets a blank page. Could probably ++ * do with an error message in between there, but whatever. ++ */ ++ if (path && ref && !cgit_ref_path_exists(filename, ref, 1)) { ++ filename = fmtalloc("%s/%s", path, ctx.repo->readme.items[0].string); ++ free_filename = 1; ++ } ++ + /* Print the calculated readme, either from the git repo or from the + * filesystem, while applying the about-filter. + */ +-- +2.24.1.735.g03f4e72817-goog + diff --git a/web/cgit-taz/0003-cgit_subtree_about_links.patch b/web/cgit-taz/0003-cgit_subtree_about_links.patch new file mode 100644 index 0000000000..6b3d0a70b1 --- /dev/null +++ b/web/cgit-taz/0003-cgit_subtree_about_links.patch @@ -0,0 +1,50 @@ +From 531b55dc96bb7ee2ce52a3612021e1c1f4ddac8a Mon Sep 17 00:00:00 2001 +From: Vincent Ambo +Date: Sat, 21 Dec 2019 23:27:28 +0000 +Subject: [PATCH 3/3] feat(ui-shared): Generate links to about pages from + subtrees + +If you're on tree/foo/bar, the about link will now point to +about/foo/bar. + +Currently the annoying thing about this is that it will also do it for +files. +--- + ui-shared.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/ui-shared.c b/ui-shared.c +index c7c3754..c37835a 100644 +--- a/ui-shared.c ++++ b/ui-shared.c +@@ -297,6 +297,12 @@ void cgit_tag_link(const char *name, const char *title, const char *class, + reporevlink("tag", name, title, class, tag, NULL, NULL); + } + ++void cgit_about_link(const char *name, const char *title, const char *class, ++ const char *head, const char *rev, const char *path) ++{ ++ reporevlink("about", name, title, class, head, rev, path); ++} ++ + void cgit_tree_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path) + { +@@ -985,10 +991,10 @@ void cgit_print_pageheader(void) + + html("
\n"); + if (ctx.env.authenticated && ctx.repo) { +- if (ctx.repo->readme.nr) +- reporevlink("about", "about", NULL, +- hc("about"), ctx.qry.head, NULL, +- NULL); ++ if (ctx.repo->readme.nr) { ++ cgit_about_link("about", NULL, hc("about"), ctx.qry.head, ++ ctx.qry.sha1, ctx.qry.vpath); ++ } + cgit_summary_link("summary", NULL, hc("summary"), + ctx.qry.head); + cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head, +-- +2.24.1.735.g03f4e72817-goog + diff --git a/web/cgit-taz/cgit_depot_url.patch b/web/cgit-taz/cgit_depot_url.patch deleted file mode 100644 index cb81a2a49a..0000000000 --- a/web/cgit-taz/cgit_depot_url.patch +++ /dev/null @@ -1,97 +0,0 @@ -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 = "&"; -+ 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(""); - 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(""); diff --git a/web/cgit-taz/cgit_idx.patch b/web/cgit-taz/cgit_idx.patch deleted file mode 100644 index 67dbc0c7ab..0000000000 --- a/web/cgit-taz/cgit_idx.patch +++ /dev/null @@ -1,13 +0,0 @@ -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 index c615d3bcb8..7dc5d9070a 100644 --- a/web/cgit-taz/default.nix +++ b/web/cgit-taz/default.nix @@ -9,10 +9,13 @@ with pkgs.third_party; let - # Patched version of cgit that builds repository URLs correctly - # (since only one repository is served) + # Patched version of cgit that has monorepo-specific features. monocgit = cgit.overrideAttrs(old: { - patches = old.patches ++ [ ./cgit_depot_url.patch ]; + patches = old.patches ++ [ + ./0001-cgit_monorepo_urls.patch + ./0002-cgit_subtree_readmes.patch + ./0003-cgit_subtree_about_links.patch + ]; }); cgitConfig = writeText "cgitrc" '' @@ -68,7 +71,10 @@ let #ifdef CGI_LD_LIBRARY_PATH ''; thttpdCgit = thttpd.overrideAttrs(old: { - patches = [ ./cgit_idx.patch thttpdConfigPatch ]; + patches = [ + ./thttpd_cgi_idx.patch + thttpdConfigPatch + ]; }); in writeShellScriptBin "cgit-launch" '' exec ${thttpdCgit}/bin/thttpd -D -C ${thttpdConfig} diff --git a/web/cgit-taz/thttpd_cgi_idx.patch b/web/cgit-taz/thttpd_cgi_idx.patch new file mode 100644 index 0000000000..67dbc0c7ab --- /dev/null +++ b/web/cgit-taz/thttpd_cgi_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. -- cgit 1.4.1