diff options
author | June McEnroe | 2019-12-19 21:55:05 +0000 |
---|---|---|
committer | June McEnroe | 2022-02-13 11:51:54 -0500 |
commit | 41a17adafa443dc5a0d42d5d21fb02230b9005b7 (patch) | |
tree | 95eb31032fc980f0c9b4955ba45139038d8af1bf | |
parent | Disallow blame in robots.txt (diff) | |
download | cgit-41a17adafa443dc5a0d42d5d21fb02230b9005b7.tar.gz cgit-41a17adafa443dc5a0d42d5d21fb02230b9005b7.zip |
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.
-rw-r--r-- | ui-tree.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/ui-tree.c b/ui-tree.c index 45e930e..438b001 100644 --- a/ui-tree.c +++ b/ui-tree.c | |||
@@ -206,9 +206,11 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, | |||
206 | struct walk_tree_context *walk_tree_ctx = cbdata; | 206 | struct walk_tree_context *walk_tree_ctx = cbdata; |
207 | char *name; | 207 | char *name; |
208 | struct strbuf fullpath = STRBUF_INIT; | 208 | struct strbuf fullpath = STRBUF_INIT; |
209 | struct strbuf linkpath = STRBUF_INIT; | ||
209 | struct strbuf class = STRBUF_INIT; | 210 | struct strbuf class = STRBUF_INIT; |
210 | enum object_type type; | 211 | enum object_type type; |
211 | unsigned long size = 0; | 212 | unsigned long size = 0; |
213 | char *buf; | ||
212 | 214 | ||
213 | name = xstrdup(pathname); | 215 | name = xstrdup(pathname); |
214 | strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", | 216 | 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, | |||
220 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 222 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
221 | name, | 223 | name, |
222 | oid_to_hex(oid)); | 224 | oid_to_hex(oid)); |
223 | free(name); | 225 | goto cleanup; |
224 | return 0; | ||
225 | } | 226 | } |
226 | } | 227 | } |
227 | 228 | ||
@@ -241,6 +242,21 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, | |||
241 | cgit_tree_link(name, NULL, class.buf, ctx.qry.head, | 242 | cgit_tree_link(name, NULL, class.buf, ctx.qry.head, |
242 | walk_tree_ctx->curr_rev, fullpath.buf); | 243 | walk_tree_ctx->curr_rev, fullpath.buf); |
243 | } | 244 | } |
245 | if (S_ISLNK(mode)) { | ||
246 | html(" -> "); | ||
247 | buf = read_object_file(oid, &type, &size); | ||
248 | if (!buf) { | ||
249 | htmlf("Error reading object: %s", oid_to_hex(oid)); | ||
250 | goto cleanup; | ||
251 | } | ||
252 | strbuf_addbuf(&linkpath, &fullpath); | ||
253 | strbuf_addf(&linkpath, "/../%s", buf); | ||
254 | strbuf_normalize_path(&linkpath); | ||
255 | cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, | ||
256 | walk_tree_ctx->curr_rev, linkpath.buf); | ||
257 | free(buf); | ||
258 | strbuf_release(&linkpath); | ||
259 | } | ||
244 | htmlf("</td><td class='ls-size'>%li</td>", size); | 260 | htmlf("</td><td class='ls-size'>%li</td>", size); |
245 | 261 | ||
246 | html("<td>"); | 262 | html("<td>"); |
@@ -257,6 +273,8 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, | |||
257 | cgit_blame_link("blame", NULL, "button", ctx.qry.head, | 273 | cgit_blame_link("blame", NULL, "button", ctx.qry.head, |
258 | walk_tree_ctx->curr_rev, fullpath.buf); | 274 | walk_tree_ctx->curr_rev, fullpath.buf); |
259 | html("</td></tr>\n"); | 275 | html("</td></tr>\n"); |
276 | |||
277 | cleanup: | ||
260 | free(name); | 278 | free(name); |
261 | strbuf_release(&fullpath); | 279 | strbuf_release(&fullpath); |
262 | strbuf_release(&class); | 280 | strbuf_release(&class); |