cgit and symlinks

John Keeping john at keeping.me.uk
Tue Mar 7 00:35:25 CET 2017


On Mon, Mar 06, 2017 at 11:42:14AM +0100, Olliver Schinagl wrote:
> Having said that, I was playing around with a simple script and noticed 
> wget gave 404's on symlinks.
> 
> As an example:
> 
> http://git.schinagl.nl/debootstrap.git/plain/scripts/stretch
> 
> at the very least I would expect the content of the link as for example 
> github shows:
> https://raw.githubusercontent.com/oliv3r/debootstrap/master/scripts/stretch
> 
> having said that, even github handles it wrong imo, as I would expect 
> the webserver to 'get' a symlink and thus just follow the symlink and 
> thus get the content of the file (in raw/plain mode).
> 
> I have tried googeling and checked cgitrc for my 0.12 but have not found 
> anything yet.
> 
> Did I simply miss something configuration wise?

Nope, it looks like we simply ignore symlinks in the plain UI.  Below is
a patch to fix this by printing the content in the same we as in the
tree UI.

We can't reliably follow the link because there is no guarantee that the
target lies within the repository and I don't know what we would output
for the case where we can't display the target.

-- >8 --
Subject: [PATCH] ui-plain: print symlink content

We currently ignore symlinks in ui-plain, leading to a 404.  In ui-tree
we print the content of the blob (that is, the path to the target of the
link), so it makes sense to do the same here.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-plain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-plain.c b/ui-plain.c
index 8d541e3..01e8b36 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -135,7 +135,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
 	struct walk_tree_context *walk_tree_ctx = cbdata;
 
 	if (base->len == walk_tree_ctx->match_baselen) {
-		if (S_ISREG(mode)) {
+		if (S_ISREG(mode) || S_ISLNK(mode)) {
 			if (print_object(sha1, pathname))
 				walk_tree_ctx->match = 1;
 		} else if (S_ISDIR(mode)) {
-- 
2.12.0.377.gf910686b23.dirty



More information about the CGit mailing list