cgit

commit 3cb5d86dc68bab4883bf5a7cbc90f3e266237355

Author: Jason A. Donenfeld <Jason@zx2c4.com>

ui-summary: Use default branch for readme if : prefix

If the readme value begins with ":", and has no specified branch before
it, use the repository's default branch.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

 cgitrc.5.txt | 4 +++-
 ui-summary.c | 7 ++++++-


diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 9b803b372ad97832b245f0e1b8adf78ac8d1d388..8a0a9c952a269a60773884ab99c158bea3ea21eb 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -505,7 +505,9 @@ repo.readme::
 	A path (relative to <repo.path>) which specifies a file to include
 	verbatim as the "About" page for this repo. You may also specify a
 	git refspec by head or by hash by prepending the refspec followed by
-	a colon. For example, "master:docs/readme.mkd" Default value: <readme>.
+	a colon. For example, "master:docs/readme.mkd". If the value begins
+	with a colon, i.e. ":docs/readme.rst", the default branch of the
+	repository will be used. Default value: <readme>.
 
 repo.snapshots::
 	A mask of allowed snapshot-formats for this repo, restricted by the




diff --git a/ui-summary.c b/ui-summary.c
index f965b320b4033a01aca83adac5f3b6f91dfeab7a..abf914ea7b9bef132613045e925f6528b75fea2d 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -108,7 +108,12 @@ 	/* Check if the readme is tracked in the git repo. */
 	colon = strchr(ctx.repo->readme, ':');
 	if (colon && strlen(colon) > 1) {
 		*colon = '\0';
-		ref = ctx.repo->readme;
+		/* If it starts with a colon, we want to use
+		 * the default branch */
+		if (colon == ctx.repo->readme && ctx.repo->defbranch)
+			ref = ctx.repo->defbranch;
+		else
+			ref = ctx.repo->readme;
 		ctx.repo->readme = colon + 1;
 		if (!(*ctx.repo->readme))
 			return;