Commit a0f6669bdb74e58b0ddb3f4283209cd5e58c0eb9

Parents: ce2062d9e29bf165ba8a70bfc92ff3ab08338d53

From: Christian Hesse <mail@eworm.de>
Date: Mon Jan 10 10:15:33 2022 +0700

about: allow to give head from query
Reading the README from repository used to be limited to default
branch or a branch given in configuration. Let's allow a branch
from query if not specified explicitly.

Signed-off-by: Christian Hesse <mail@eworm.de>

Stats

cgit.c +5/-3
cgitrc.5.txt +5/-5

Changeset

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
diff --git a/cgit.c b/cgit.c
index 4b2d86c88129c871a41fd15727e5e61c1ef49359..2de6d7f84c530f30851c2b3931eaec11ca722b1c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -507,9 +507,11 @@
 	/* Check if the readme is tracked in the git repo. */
 	colon = strchr(readme, ':');
 	if (colon && strlen(colon) > 1) {
-		/* If it starts with a colon, we want to use
-		 * the default branch */
-		if (colon == readme && repo->defbranch)
+		/* If it starts with a colon, we want to use head given
+		 * from query or the default branch */
+		if (colon == readme && ctx.qry.head)
+			*ref = xstrdup(ctx.qry.head);
+		else if (colon == readme && repo->defbranch)
 			*ref = xstrdup(repo->defbranch);
 		else
 			*ref = xstrndup(readme, colon - readme);
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 33a6a8c0c75832645a0d1c5b9b2b65d4d8cf2466..d9eb3b02d322e67759fb413e0f9fd27375fbeab1 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -579,11 +579,11 @@ 	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". If the value begins
-	with a colon, i.e. ":docs/readme.rst", the default branch of the
-	repository will be used. Sharing any file will expose that entire
-	directory tree to the "/about/PATH" endpoints, so be sure that there
-	are no non-public files located in the same directory as the readme
-	file. Default value: <readme>.
+	with a colon, i.e. ":docs/readme.rst", the head giving in query or
+	the default branch of the repository will be used. Sharing any file
+	will expose that entire directory tree to the "/about/PATH" endpoints,
+	so be sure that there are no non-public files located in the same
+	directory as the readme file. Default value: <readme>.
 
 repo.section::
 	Override the current section name for this repository. Default value: