about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-21T22·58+0000
committerVincent Ambo <Vincent Ambo>2020-01-11T23·47+0000
commit0294eec9da79ba3bebf351c22d04c67b22dc920f (patch)
tree8daaabde4bead14f5b80446434e8afcc62e57d4d
parent8de22f654c725999b6a2ce39edfbb78806452e1a (diff)
feat(third_party/cgit): Use README at each subtree r/376
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.
-rw-r--r--third_party/cgit/ui-summary.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/third_party/cgit/ui-summary.c b/third_party/cgit/ui-summary.c
index 947812a814ca..d1bb6a59faea 100644
--- a/third_party/cgit/ui-summary.c
+++ b/third_party/cgit/ui-summary.c
@@ -128,6 +128,18 @@ void cgit_print_repo_readme(const 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.
 	 */