blob: d26e35e24fa8fa94152994d6538c02f148d27295 [file] [log] [blame]
Lars Hjemli06fe0c22006-12-13 00:13:27 +01001/* ui-tree.c: functions for tree output
2 *
Jeff Smith1649afd2017-10-01 23:39:09 -05003 * Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com>
Lars Hjemli06fe0c22006-12-13 00:13:27 +01004 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
John Keeping8f208792013-04-06 11:37:59 +010010#include "ui-tree.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010011#include "html.h"
Lars Hjemlia4d1ca12008-03-24 16:50:57 +010012#include "ui-shared.h"
Lars Hjemli06fe0c22006-12-13 00:13:27 +010013
Lukas Fleischer210a5712013-03-03 17:22:30 +010014struct walk_tree_context {
15 char *curr_rev;
16 char *match_path;
17 int state;
18};
Lars Hjemli06fe0c22006-12-13 00:13:27 +010019
Lars Hjemli46b7abe2009-07-31 16:55:27 +020020static void print_text_buffer(const char *name, char *buf, unsigned long size)
Lars Hjemliae1d4d72009-01-31 17:45:48 +010021{
22 unsigned long lineno, idx;
Peter Wu4468ec12013-10-03 12:17:23 +020023 const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
Lars Hjemliae1d4d72009-01-31 17:45:48 +010024
25 html("<table summary='blob content' class='blob'>\n");
Lars Hjemli46b7abe2009-07-31 16:55:27 +020026
Lars Hjemlib0f946b2009-08-21 14:26:52 +020027 if (ctx.cfg.enable_tree_linenumbers) {
Florian Pritzd67cc7f2009-08-09 20:42:45 +000028 html("<tr><td class='linenumbers'><pre>");
29 idx = 0;
30 lineno = 0;
Lukas Fleischer53bc7472013-03-03 16:04:29 +010031
Florian Pritzd67cc7f2009-08-09 20:42:45 +000032 if (size) {
33 htmlf(numberfmt, ++lineno);
Jason A. Donenfeldbdae1d82013-03-03 23:21:33 -050034 while (idx < size - 1) { // skip absolute last newline
Florian Pritzd67cc7f2009-08-09 20:42:45 +000035 if (buf[idx] == '\n')
36 htmlf(numberfmt, ++lineno);
37 idx++;
38 }
Eric Wong11297362009-03-14 18:41:47 -070039 }
Florian Pritzd67cc7f2009-08-09 20:42:45 +000040 html("</pre></td>\n");
Lars Hjemliae1d4d72009-01-31 17:45:48 +010041 }
Florian Pritzd67cc7f2009-08-09 20:42:45 +000042 else {
43 html("<tr>\n");
44 }
Florian Pritz03389d62009-08-09 13:43:18 +000045
46 if (ctx.repo->source_filter) {
John Keeping3d8a6502014-01-12 17:13:50 +000047 char *filter_arg = xstrdup(name);
Florian Pritz03389d62009-08-09 13:43:18 +000048 html("<td class='lines'><pre><code>");
John Keeping3d8a6502014-01-12 17:13:50 +000049 cgit_open_filter(ctx.repo->source_filter, filter_arg);
Mark Lodatod187b982010-09-04 14:18:16 -040050 html_raw(buf, size);
Florian Pritz03389d62009-08-09 13:43:18 +000051 cgit_close_filter(ctx.repo->source_filter);
John Keeping3d8a6502014-01-12 17:13:50 +000052 free(filter_arg);
Florian Pritz03389d62009-08-09 13:43:18 +000053 html("</code></pre></td></tr></table>\n");
54 return;
55 }
56
Lars Hjemliae1d4d72009-01-31 17:45:48 +010057 html("<td class='lines'><pre><code>");
58 html_txt(buf);
59 html("</code></pre></td></tr></table>\n");
60}
61
Lars Hjemli6063e7b2009-02-12 11:26:14 +010062#define ROWLEN 32
63
Lars Hjemliae1d4d72009-01-31 17:45:48 +010064static void print_binary_buffer(char *buf, unsigned long size)
65{
66 unsigned long ofs, idx;
Lars Hjemli6063e7b2009-02-12 11:26:14 +010067 static char ascii[ROWLEN + 1];
Lars Hjemliae1d4d72009-01-31 17:45:48 +010068
69 html("<table summary='blob content' class='bin-blob'>\n");
70 html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>");
Lars Hjemli6063e7b2009-02-12 11:26:14 +010071 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) {
Mark Lodatoe4ddc8f2010-09-04 11:30:18 -040072 htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs);
Lars Hjemli6063e7b2009-02-12 11:26:14 +010073 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
Lars Hjemliae1d4d72009-01-31 17:45:48 +010074 htmlf("%*s%02x",
75 idx == 16 ? 4 : 1, "",
76 buf[idx] & 0xff);
77 html(" </td><td class='hex'>");
Lars Hjemli6063e7b2009-02-12 11:26:14 +010078 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
79 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.';
80 ascii[idx] = '\0';
81 html_txt(ascii);
Lars Hjemliae1d4d72009-01-31 17:45:48 +010082 html("</td></tr>\n");
83 }
84 html("</table>\n");
85}
86
John Keeping35a08292018-06-18 14:22:24 +080087static void print_buffer(const char *basename, char *buf, unsigned long size)
88{
89 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
90 htmlf("<div class='error'>blob size (%ldKB) exceeds display size limit (%dKB).</div>",
91 size / 1024, ctx.cfg.max_blob_size);
92 return;
93 }
94
95 if (buffer_is_binary(buf, size))
96 print_binary_buffer(buf, size);
97 else
98 print_text_buffer(basename, buf, size);
99}
100
Christian Hesse255b78f2018-06-04 18:49:28 +0200101static void print_object(const struct object_id *oid, char *path, const char *basename, const char *rev)
Lars Hjemliffc69732007-06-16 20:20:42 +0200102{
103 enum object_type type;
Lars Hjemli0835ffe2007-09-20 00:21:47 +0200104 char *buf;
Lars Hjemliae1d4d72009-01-31 17:45:48 +0100105 unsigned long size;
Lars Hjemliffc69732007-06-16 20:20:42 +0200106
Christian Hesse255b78f2018-06-04 18:49:28 +0200107 type = oid_object_info(the_repository, oid, &size);
Lars Hjemliffc69732007-06-16 20:20:42 +0200108 if (type == OBJ_BAD) {
John Keeping9c70c0b2015-08-14 12:47:20 +0100109 cgit_print_error_page(404, "Not found",
Christian Hesse255b78f2018-06-04 18:49:28 +0200110 "Bad object name: %s", oid_to_hex(oid));
Lars Hjemliffc69732007-06-16 20:20:42 +0200111 return;
112 }
113
Christian Hesse255b78f2018-06-04 18:49:28 +0200114 buf = read_object_file(oid, &type, &size);
Lars Hjemliffc69732007-06-16 20:20:42 +0200115 if (!buf) {
John Keeping9c70c0b2015-08-14 12:47:20 +0100116 cgit_print_error_page(500, "Internal server error",
Christian Hesse255b78f2018-06-04 18:49:28 +0200117 "Error reading object %s", oid_to_hex(oid));
Lars Hjemliffc69732007-06-16 20:20:42 +0200118 return;
119 }
120
Jeff Smith9337c7e2017-10-01 23:39:06 -0500121 cgit_set_title_from_path(path);
Jason A. Donenfeld23f7dad2016-01-18 15:56:45 +0100122
John Keeping9c70c0b2015-08-14 12:47:20 +0100123 cgit_print_layout_start();
Christian Hesse255b78f2018-06-04 18:49:28 +0200124 htmlf("blob: %s (", oid_to_hex(oid));
Lars Hjemli65b7b872008-08-06 11:07:13 +0200125 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
Lukas Fleischerfb5a3732013-03-03 16:45:14 +0100126 rev, path);
Jeff Smith1649afd2017-10-01 23:39:09 -0500127 if (ctx.cfg.enable_blame) {
128 html(") (");
129 cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
130 rev, path);
131 }
Johan Herland48f7b982010-06-10 01:09:30 +0200132 html(")\n");
Michael Krelind6b01da2007-07-21 19:51:47 +0200133
John Keeping35a08292018-06-18 14:22:24 +0800134 print_buffer(basename, buf, size);
Andy Green77088592018-06-13 10:02:00 +0800135
136 free(buf);
Lars Hjemliffc69732007-06-16 20:20:42 +0200137}
138
John Keeping000cf292016-07-13 20:19:42 +0100139struct single_tree_ctx {
140 struct strbuf *path;
Jeff Smith86a6d352017-08-09 19:02:56 -0500141 struct object_id oid;
John Keeping000cf292016-07-13 20:19:42 +0100142 char *name;
143 size_t count;
144};
145
Christian Hesse255b78f2018-06-04 18:49:28 +0200146static int single_tree_cb(const struct object_id *oid, struct strbuf *base,
John Keeping000cf292016-07-13 20:19:42 +0100147 const char *pathname, unsigned mode, int stage,
148 void *cbdata)
149{
150 struct single_tree_ctx *ctx = cbdata;
151
152 if (++ctx->count > 1)
153 return -1;
154
155 if (!S_ISDIR(mode)) {
156 ctx->count = 2;
157 return -1;
158 }
159
160 ctx->name = xstrdup(pathname);
Christian Hesse255b78f2018-06-04 18:49:28 +0200161 oidcpy(&ctx->oid, oid);
John Keeping000cf292016-07-13 20:19:42 +0100162 strbuf_addf(ctx->path, "/%s", pathname);
163 return 0;
164}
165
Christian Hesse255b78f2018-06-04 18:49:28 +0200166static void write_tree_link(const struct object_id *oid, char *name,
John Keeping000cf292016-07-13 20:19:42 +0100167 char *rev, struct strbuf *fullpath)
168{
169 size_t initial_length = fullpath->len;
170 struct tree *tree;
171 struct single_tree_ctx tree_ctx = {
172 .path = fullpath,
173 .count = 1,
174 };
175 struct pathspec paths = {
176 .nr = 0
177 };
178
Christian Hesse255b78f2018-06-04 18:49:28 +0200179 oidcpy(&tree_ctx.oid, oid);
John Keeping000cf292016-07-13 20:19:42 +0100180
181 while (tree_ctx.count == 1) {
182 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev,
183 fullpath->buf);
184
Jeff Smith86a6d352017-08-09 19:02:56 -0500185 tree = lookup_tree(&tree_ctx.oid);
John Keeping000cf292016-07-13 20:19:42 +0100186 if (!tree)
187 return;
188
189 free(tree_ctx.name);
190 tree_ctx.name = NULL;
191 tree_ctx.count = 0;
192
193 read_tree_recursive(tree, "", 0, 1, &paths, single_tree_cb,
194 &tree_ctx);
195
196 if (tree_ctx.count != 1)
197 break;
198
199 html(" / ");
200 name = tree_ctx.name;
201 }
202
203 strbuf_setlen(fullpath, initial_length);
204}
Lars Hjemliffc69732007-06-16 20:20:42 +0200205
Christian Hesse255b78f2018-06-04 18:49:28 +0200206static int ls_item(const struct object_id *oid, struct strbuf *base,
Christian Hesse7358f632015-02-07 14:18:28 +0100207 const char *pathname, unsigned mode, int stage, void *cbdata)
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100208{
Lukas Fleischer210a5712013-03-03 17:22:30 +0100209 struct walk_tree_context *walk_tree_ctx = cbdata;
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100210 char *name;
John Keepingfb3655d2013-04-06 10:28:57 +0100211 struct strbuf fullpath = STRBUF_INIT;
212 struct strbuf class = STRBUF_INIT;
Lars Hjemli61c3ca92007-05-08 22:40:59 +0200213 enum object_type type;
Lars Hjemlided93932007-05-11 12:12:48 +0200214 unsigned long size = 0;
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100215
Lars Hjemli61c3ca92007-05-08 22:40:59 +0200216 name = xstrdup(pathname);
John Keepingfb3655d2013-04-06 10:28:57 +0100217 strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "",
218 ctx.qry.path ? "/" : "", name);
Lars Hjemli44947bf2007-06-17 01:23:08 +0200219
Lars Hjemli08a87572008-05-20 22:32:22 +0200220 if (!S_ISGITLINK(mode)) {
Christian Hesse255b78f2018-06-04 18:49:28 +0200221 type = oid_object_info(the_repository, oid, &size);
Lars Hjemli08a87572008-05-20 22:32:22 +0200222 if (type == OBJ_BAD) {
223 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
224 name,
Christian Hesse255b78f2018-06-04 18:49:28 +0200225 oid_to_hex(oid));
Christian Hesse896cd692015-10-09 13:15:44 +0200226 free(name);
Lars Hjemli08a87572008-05-20 22:32:22 +0200227 return 0;
228 }
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100229 }
Lars Hjemli44947bf2007-06-17 01:23:08 +0200230
Lars Hjemli426032f2007-06-17 13:17:00 +0200231 html("<tr><td class='ls-mode'>");
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +0100232 cgit_print_filemode(mode);
Lars Hjemli426032f2007-06-17 13:17:00 +0200233 html("</td><td>");
Jeffrey C. Olliee651cb02007-06-04 12:28:56 -0500234 if (S_ISGITLINK(mode)) {
Christian Hesse255b78f2018-06-04 18:49:28 +0200235 cgit_submodule_link("ls-mod", fullpath.buf, oid_to_hex(oid));
Lars Hjemli61c3ca92007-05-08 22:40:59 +0200236 } else if (S_ISDIR(mode)) {
Christian Hesse255b78f2018-06-04 18:49:28 +0200237 write_tree_link(oid, name, walk_tree_ctx->curr_rev,
John Keeping000cf292016-07-13 20:19:42 +0100238 &fullpath);
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100239 } else {
John Keepingfb3655d2013-04-06 10:28:57 +0100240 char *ext = strrchr(name, '.');
241 strbuf_addstr(&class, "ls-blob");
242 if (ext)
243 strbuf_addf(&class, " %s", ext + 1);
244 cgit_tree_link(name, NULL, class.buf, ctx.qry.head,
245 walk_tree_ctx->curr_rev, fullpath.buf);
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100246 }
Lars Hjemli426032f2007-06-17 13:17:00 +0200247 htmlf("</td><td class='ls-size'>%li</td>", size);
Lars Hjemli9fb53af2007-05-14 11:10:59 +0200248
Lars Hjemli48c487d2007-06-17 13:57:51 +0200249 html("<td>");
Lukas Fleischer210a5712013-03-03 17:22:30 +0100250 cgit_log_link("log", NULL, "button", ctx.qry.head,
John Keepingfb3655d2013-04-06 10:28:57 +0100251 walk_tree_ctx->curr_rev, fullpath.buf, 0, NULL, NULL,
John Keeping30304d82015-08-12 15:55:28 +0100252 ctx.qry.showmsg, 0);
Lars Hjemli837d4642008-12-07 13:34:42 +0100253 if (ctx.repo->max_stats)
254 cgit_stats_link("stats", NULL, "button", ctx.qry.head,
John Keepingfb3655d2013-04-06 10:28:57 +0100255 fullpath.buf);
Lars Hjemli6857bec2011-06-15 10:04:13 +0200256 if (!S_ISGITLINK(mode))
Lukas Fleischer210a5712013-03-03 17:22:30 +0100257 cgit_plain_link("plain", NULL, "button", ctx.qry.head,
John Keepingfb3655d2013-04-06 10:28:57 +0100258 walk_tree_ctx->curr_rev, fullpath.buf);
Jeff Smith1649afd2017-10-01 23:39:09 -0500259 if (!S_ISDIR(mode) && ctx.cfg.enable_blame)
260 cgit_blame_link("blame", NULL, "button", ctx.qry.head,
261 walk_tree_ctx->curr_rev, fullpath.buf);
Lars Hjemli48c487d2007-06-17 13:57:51 +0200262 html("</td></tr>\n");
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100263 free(name);
John Keepingfb3655d2013-04-06 10:28:57 +0100264 strbuf_release(&fullpath);
265 strbuf_release(&class);
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100266 return 0;
267}
268
John Keepinge3d3fff2015-03-08 16:32:16 +0000269static void ls_head(void)
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100270{
John Keeping9c70c0b2015-08-14 12:47:20 +0100271 cgit_print_layout_start();
Lars Hjemli29154832007-11-11 13:04:28 +0100272 html("<table summary='tree listing' class='list'>\n");
Lars Hjemli777faf72007-01-28 00:39:26 +0100273 html("<tr class='nohover'>");
Lars Hjemlia5304282006-12-17 23:55:53 +0100274 html("<th class='left'>Mode</th>");
275 html("<th class='left'>Name</th>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +0100276 html("<th class='right'>Size</th>");
Lars Hjemli9fb53af2007-05-14 11:10:59 +0200277 html("<th/>");
Lars Hjemlia5304282006-12-17 23:55:53 +0100278 html("</tr>\n");
Lars Hjemliffc69732007-06-16 20:20:42 +0200279}
280
John Keepinge3d3fff2015-03-08 16:32:16 +0000281static void ls_tail(void)
Lars Hjemliffc69732007-06-16 20:20:42 +0200282{
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100283 html("</table>\n");
John Keeping9c70c0b2015-08-14 12:47:20 +0100284 cgit_print_layout_end();
Lars Hjemliffc69732007-06-16 20:20:42 +0200285}
286
Jeff Smith86a6d352017-08-09 19:02:56 -0500287static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_context *walk_tree_ctx)
Lars Hjemliffc69732007-06-16 20:20:42 +0200288{
289 struct tree *tree;
John Keepingc1633c62013-03-02 12:32:11 +0000290 struct pathspec paths = {
291 .nr = 0
292 };
Lars Hjemliffc69732007-06-16 20:20:42 +0200293
Jeff Smith86a6d352017-08-09 19:02:56 -0500294 tree = parse_tree_indirect(oid);
Lars Hjemliffc69732007-06-16 20:20:42 +0200295 if (!tree) {
John Keeping9c70c0b2015-08-14 12:47:20 +0100296 cgit_print_error_page(404, "Not found",
Christian Hesse255b78f2018-06-04 18:49:28 +0200297 "Not a tree object: %s", oid_to_hex(oid));
Lars Hjemliffc69732007-06-16 20:20:42 +0200298 return;
299 }
300
301 ls_head();
Lukas Fleischer210a5712013-03-03 17:22:30 +0100302 read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx);
Lars Hjemliffc69732007-06-16 20:20:42 +0200303 ls_tail();
304}
305
306
Christian Hesse255b78f2018-06-04 18:49:28 +0200307static int walk_tree(const struct object_id *oid, struct strbuf *base,
Christian Hesse7358f632015-02-07 14:18:28 +0100308 const char *pathname, unsigned mode, int stage, void *cbdata)
Lars Hjemliffc69732007-06-16 20:20:42 +0200309{
Lukas Fleischer210a5712013-03-03 17:22:30 +0100310 struct walk_tree_context *walk_tree_ctx = cbdata;
Lars Hjemliffc69732007-06-16 20:20:42 +0200311
Lukas Fleischer210a5712013-03-03 17:22:30 +0100312 if (walk_tree_ctx->state == 0) {
John Keepinge18a85b2016-08-13 11:54:46 +0100313 struct strbuf buffer = STRBUF_INIT;
314
315 strbuf_addbuf(&buffer, base);
316 strbuf_addstr(&buffer, pathname);
317 if (strcmp(walk_tree_ctx->match_path, buffer.buf))
Lars Hjemliffc69732007-06-16 20:20:42 +0200318 return READ_TREE_RECURSIVE;
319
320 if (S_ISDIR(mode)) {
Lukas Fleischer210a5712013-03-03 17:22:30 +0100321 walk_tree_ctx->state = 1;
Jeff Smith9337c7e2017-10-01 23:39:06 -0500322 cgit_set_title_from_path(buffer.buf);
John Keepinge18a85b2016-08-13 11:54:46 +0100323 strbuf_release(&buffer);
Lars Hjemliffc69732007-06-16 20:20:42 +0200324 ls_head();
325 return READ_TREE_RECURSIVE;
326 } else {
John Keeping9c70c0b2015-08-14 12:47:20 +0100327 walk_tree_ctx->state = 2;
Christian Hesse255b78f2018-06-04 18:49:28 +0200328 print_object(oid, buffer.buf, pathname, walk_tree_ctx->curr_rev);
John Keepinge18a85b2016-08-13 11:54:46 +0100329 strbuf_release(&buffer);
Lars Hjemliffc69732007-06-16 20:20:42 +0200330 return 0;
331 }
332 }
Christian Hesse255b78f2018-06-04 18:49:28 +0200333 ls_item(oid, base, pathname, mode, stage, walk_tree_ctx);
Lars Hjemliffc69732007-06-16 20:20:42 +0200334 return 0;
335}
336
Lars Hjemliffc69732007-06-16 20:20:42 +0200337/*
338 * Show a tree or a blob
339 * rev: the commit pointing at the root tree object
340 * path: path to tree or blob
341 */
342void cgit_print_tree(const char *rev, char *path)
343{
Christian Hesse9dd3c5e2016-09-29 22:17:07 +0200344 struct object_id oid;
Lars Hjemliffc69732007-06-16 20:20:42 +0200345 struct commit *commit;
John Keepingc1633c62013-03-02 12:32:11 +0000346 struct pathspec_item path_items = {
347 .match = path,
348 .len = path ? strlen(path) : 0
349 };
350 struct pathspec paths = {
351 .nr = path ? 1 : 0,
352 .items = &path_items
353 };
Lukas Fleischer210a5712013-03-03 17:22:30 +0100354 struct walk_tree_context walk_tree_ctx = {
355 .match_path = path,
356 .state = 0
357 };
Lars Hjemliffc69732007-06-16 20:20:42 +0200358
359 if (!rev)
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100360 rev = ctx.qry.head;
Lars Hjemliffc69732007-06-16 20:20:42 +0200361
Christian Hesse9dd3c5e2016-09-29 22:17:07 +0200362 if (get_oid(rev, &oid)) {
John Keeping9c70c0b2015-08-14 12:47:20 +0100363 cgit_print_error_page(404, "Not found",
364 "Invalid revision name: %s", rev);
Lars Hjemliffc69732007-06-16 20:20:42 +0200365 return;
366 }
Jeff Smith86a6d352017-08-09 19:02:56 -0500367 commit = lookup_commit_reference(&oid);
Lars Hjemliffc69732007-06-16 20:20:42 +0200368 if (!commit || parse_commit(commit)) {
John Keeping9c70c0b2015-08-14 12:47:20 +0100369 cgit_print_error_page(404, "Not found",
370 "Invalid commit reference: %s", rev);
Lars Hjemliffc69732007-06-16 20:20:42 +0200371 return;
372 }
373
Lukas Fleischer985d6ca2013-03-04 13:25:36 +0100374 walk_tree_ctx.curr_rev = xstrdup(rev);
375
Lars Hjemliffc69732007-06-16 20:20:42 +0200376 if (path == NULL) {
Christian Hesse255b78f2018-06-04 18:49:28 +0200377 ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx);
Lukas Fleischer985d6ca2013-03-04 13:25:36 +0100378 goto cleanup;
Lars Hjemliffc69732007-06-16 20:20:42 +0200379 }
380
Christian Hesse255b78f2018-06-04 18:49:28 +0200381 read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
Lukas Fleischer210a5712013-03-03 17:22:30 +0100382 if (walk_tree_ctx.state == 1)
Lukas Fleischerbfe57662013-03-03 16:55:21 +0100383 ls_tail();
John Keeping9c70c0b2015-08-14 12:47:20 +0100384 else if (walk_tree_ctx.state == 2)
385 cgit_print_layout_end();
386 else
387 cgit_print_error_page(404, "Not found", "Path not found");
Lukas Fleischer985d6ca2013-03-04 13:25:36 +0100388
389cleanup:
390 free(walk_tree_ctx.curr_rev);
Lars Hjemli06fe0c22006-12-13 00:13:27 +0100391}