From b6dc85faf437892e0aecec3cfb01ad6b3433628e Mon Sep 17 00:00:00 2001
From: June McEnroe <june@causal.agency>
Date: Thu, 19 Dec 2019 21:55:05 +0000
Subject: Show symlink targets in tree listing

Add links to symbolic link targets in tree listings, formatted like
"ls -l".  Path normalization collapses any ".." components of the link.
---
 www/git.causal.agency/cgit/ui-tree.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

(limited to 'www')

diff --git a/www/git.causal.agency/cgit/ui-tree.c b/www/git.causal.agency/cgit/ui-tree.c
index 45e930e7..438b0011 100644
--- a/www/git.causal.agency/cgit/ui-tree.c
+++ b/www/git.causal.agency/cgit/ui-tree.c
@@ -206,9 +206,11 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
 	struct walk_tree_context *walk_tree_ctx = cbdata;
 	char *name;
 	struct strbuf fullpath = STRBUF_INIT;
+	struct strbuf linkpath = STRBUF_INIT;
 	struct strbuf class = STRBUF_INIT;
 	enum object_type type;
 	unsigned long size = 0;
+	char *buf;
 
 	name = xstrdup(pathname);
 	strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "",
@@ -220,8 +222,7 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
 			htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
 			      name,
 			      oid_to_hex(oid));
-			free(name);
-			return 0;
+			goto cleanup;
 		}
 	}
 
@@ -241,6 +242,21 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
 		cgit_tree_link(name, NULL, class.buf, ctx.qry.head,
 			       walk_tree_ctx->curr_rev, fullpath.buf);
 	}
+	if (S_ISLNK(mode)) {
+		html(" -> ");
+		buf = read_object_file(oid, &type, &size);
+		if (!buf) {
+			htmlf("Error reading object: %s", oid_to_hex(oid));
+			goto cleanup;
+		}
+		strbuf_addbuf(&linkpath, &fullpath);
+		strbuf_addf(&linkpath, "/../%s", buf);
+		strbuf_normalize_path(&linkpath);
+		cgit_tree_link(buf, NULL, class.buf, ctx.qry.head,
+			walk_tree_ctx->curr_rev, linkpath.buf);
+		free(buf);
+		strbuf_release(&linkpath);
+	}
 	htmlf("</td><td class='ls-size'>%li</td>", size);
 
 	html("<td>");
@@ -257,6 +273,8 @@ static int ls_item(const struct object_id *oid, struct strbuf *base,
 		cgit_blame_link("blame", NULL, "button", ctx.qry.head,
 				walk_tree_ctx->curr_rev, fullpath.buf);
 	html("</td></tr>\n");
+
+cleanup:
 	free(name);
 	strbuf_release(&fullpath);
 	strbuf_release(&class);
-- 
cgit 1.4.1

e='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>June McEnroe &lt;june@causal.agency&gt;</td><td class='right'>2021-01-13 22:50:32 +0000</td></tr>
<tr><th>committer</th><td>June McEnroe &lt;june@causal.agency&gt;</td><td class='right'>2021-01-13 22:50:32 +0000</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/src/commit/doc/rfc?id=10e17478b30838229eeffeac1249e1e166cc95d5'>10e17478b30838229eeffeac1249e1e166cc95d5</a> (<a href='/src/patch/doc/rfc?id=10e17478b30838229eeffeac1249e1e166cc95d5'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/src/tree/?id=10e17478b30838229eeffeac1249e1e166cc95d5'>bbf9b33f1445ebbf4f36ec860d4d5e1f3ae9f3ed</a> /<a href='/src/tree/doc/rfc?id=10e17478b30838229eeffeac1249e1e166cc95d5'>doc/rfc</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/src/commit/doc/rfc?id=0777d0bc51fcf7ecff67521cfde1448cf08947b2'>Try to return make substitutions as single tokens</a> (<a href='/src/diff/doc/rfc?id=10e17478b30838229eeffeac1249e1e166cc95d5&amp;id2=0777d0bc51fcf7ecff67521cfde1448cf08947b2'>diff</a>)</td></tr><tr><th>download</th><td colspan='2' class='oid'><a href='/src/snapshot/src-10e17478b30838229eeffeac1249e1e166cc95d5.tar.gz'>src-10e17478b30838229eeffeac1249e1e166cc95d5.tar.gz</a><br/><a href='/src/snapshot/src-10e17478b30838229eeffeac1249e1e166cc95d5.zip'>src-10e17478b30838229eeffeac1249e1e166cc95d5.zip</a><br/></td></tr></table>
<div class='commit-subject'>Switch git.causal.agency to hilex and htagml</div><pre class='commit-msg'>Still missing a shell lexer in hilex, but well... it's shell.
</pre><div class='diffstat-header'><a href='/src/diff/?id=10e17478b30838229eeffeac1249e1e166cc95d5'>Diffstat</a> (limited to 'doc/rfc')</div><table summary='diffstat' class='diffstat'></table><div class='diffstat-summary'>0 files changed, 0 insertions, 0 deletions</div><table summary='diff' class='diff'><tr><td><pre></pre></td></tr></table></div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.causal.agency/cgit-pink/about/'>cgit-pink 1.4.1</a> (<a href='https://git-scm.com/'>git 2.36.1</a>) at 2026-10-15 03:11:46 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
