Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 1 | /* ui-tree.c: functions for tree output |
| 2 | * |
| 3 | * Copyright (C) 2006 Lars Hjemli |
| 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 9 | #include <ctype.h> |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 10 | #include "cgit.h" |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 11 | #include "html.h" |
Lars Hjemli | a4d1ca1 | 2008-03-24 16:50:57 +0100 | [diff] [blame] | 12 | #include "ui-shared.h" |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 13 | |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 14 | struct walk_tree_context { |
| 15 | char *curr_rev; |
| 16 | char *match_path; |
| 17 | int state; |
| 18 | }; |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 19 | |
Lars Hjemli | 46b7abe | 2009-07-31 16:55:27 +0200 | [diff] [blame] | 20 | static void print_text_buffer(const char *name, char *buf, unsigned long size) |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 21 | { |
| 22 | unsigned long lineno, idx; |
| 23 | const char *numberfmt = |
| 24 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
| 25 | |
| 26 | html("<table summary='blob content' class='blob'>\n"); |
Lars Hjemli | 46b7abe | 2009-07-31 16:55:27 +0200 | [diff] [blame] | 27 | |
Lars Hjemli | b0f946b | 2009-08-21 14:26:52 +0200 | [diff] [blame] | 28 | if (ctx.cfg.enable_tree_linenumbers) { |
Florian Pritz | d67cc7f | 2009-08-09 20:42:45 +0000 | [diff] [blame] | 29 | html("<tr><td class='linenumbers'><pre>"); |
| 30 | idx = 0; |
| 31 | lineno = 0; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 32 | |
Florian Pritz | d67cc7f | 2009-08-09 20:42:45 +0000 | [diff] [blame] | 33 | if (size) { |
| 34 | htmlf(numberfmt, ++lineno); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 35 | while (idx < size - 1) { // skip absolute last newline |
Florian Pritz | d67cc7f | 2009-08-09 20:42:45 +0000 | [diff] [blame] | 36 | if (buf[idx] == '\n') |
| 37 | htmlf(numberfmt, ++lineno); |
| 38 | idx++; |
| 39 | } |
Eric Wong | 1129736 | 2009-03-14 18:41:47 -0700 | [diff] [blame] | 40 | } |
Florian Pritz | d67cc7f | 2009-08-09 20:42:45 +0000 | [diff] [blame] | 41 | html("</pre></td>\n"); |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 42 | } |
Florian Pritz | d67cc7f | 2009-08-09 20:42:45 +0000 | [diff] [blame] | 43 | else { |
| 44 | html("<tr>\n"); |
| 45 | } |
Florian Pritz | 03389d6 | 2009-08-09 13:43:18 +0000 | [diff] [blame] | 46 | |
| 47 | if (ctx.repo->source_filter) { |
| 48 | html("<td class='lines'><pre><code>"); |
| 49 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
Lars Hjemli | 3ec6b30 | 2011-06-06 19:29:58 +0000 | [diff] [blame] | 50 | cgit_open_filter(ctx.repo->source_filter); |
Mark Lodato | d187b98 | 2010-09-04 14:18:16 -0400 | [diff] [blame] | 51 | html_raw(buf, size); |
Florian Pritz | 03389d6 | 2009-08-09 13:43:18 +0000 | [diff] [blame] | 52 | cgit_close_filter(ctx.repo->source_filter); |
Ferry Huberts | 3f1ebd3 | 2011-03-09 08:16:58 +0100 | [diff] [blame] | 53 | free(ctx.repo->source_filter->argv[1]); |
| 54 | ctx.repo->source_filter->argv[1] = NULL; |
Florian Pritz | 03389d6 | 2009-08-09 13:43:18 +0000 | [diff] [blame] | 55 | html("</code></pre></td></tr></table>\n"); |
| 56 | return; |
| 57 | } |
| 58 | |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 59 | html("<td class='lines'><pre><code>"); |
| 60 | html_txt(buf); |
| 61 | html("</code></pre></td></tr></table>\n"); |
| 62 | } |
| 63 | |
Lars Hjemli | 6063e7b | 2009-02-12 11:26:14 +0100 | [diff] [blame] | 64 | #define ROWLEN 32 |
| 65 | |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 66 | static void print_binary_buffer(char *buf, unsigned long size) |
| 67 | { |
| 68 | unsigned long ofs, idx; |
Lars Hjemli | 6063e7b | 2009-02-12 11:26:14 +0100 | [diff] [blame] | 69 | static char ascii[ROWLEN + 1]; |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 70 | |
| 71 | html("<table summary='blob content' class='bin-blob'>\n"); |
| 72 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
Lars Hjemli | 6063e7b | 2009-02-12 11:26:14 +0100 | [diff] [blame] | 73 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
Mark Lodato | e4ddc8f | 2010-09-04 11:30:18 -0400 | [diff] [blame] | 74 | htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs); |
Lars Hjemli | 6063e7b | 2009-02-12 11:26:14 +0100 | [diff] [blame] | 75 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 76 | htmlf("%*s%02x", |
| 77 | idx == 16 ? 4 : 1, "", |
| 78 | buf[idx] & 0xff); |
| 79 | html(" </td><td class='hex'>"); |
Lars Hjemli | 6063e7b | 2009-02-12 11:26:14 +0100 | [diff] [blame] | 80 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
| 81 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
| 82 | ascii[idx] = '\0'; |
| 83 | html_txt(ascii); |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 84 | html("</td></tr>\n"); |
| 85 | } |
| 86 | html("</table>\n"); |
| 87 | } |
| 88 | |
Lukas Fleischer | fb5a373 | 2013-03-03 16:45:14 +0100 | [diff] [blame] | 89 | static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 90 | { |
| 91 | enum object_type type; |
Lars Hjemli | 0835ffe | 2007-09-20 00:21:47 +0200 | [diff] [blame] | 92 | char *buf; |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 93 | unsigned long size; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 94 | |
| 95 | type = sha1_object_info(sha1, &size); |
| 96 | if (type == OBJ_BAD) { |
| 97 | cgit_print_error(fmt("Bad object name: %s", |
| 98 | sha1_to_hex(sha1))); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | buf = read_sha1_file(sha1, &type, &size); |
| 103 | if (!buf) { |
| 104 | cgit_print_error(fmt("Error reading object %s", |
| 105 | sha1_to_hex(sha1))); |
| 106 | return; |
| 107 | } |
| 108 | |
Johan Herland | 48f7b98 | 2010-06-10 01:09:30 +0200 | [diff] [blame] | 109 | htmlf("blob: %s (", sha1_to_hex(sha1)); |
Lars Hjemli | 65b7b87 | 2008-08-06 11:07:13 +0200 | [diff] [blame] | 110 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, |
Lukas Fleischer | fb5a373 | 2013-03-03 16:45:14 +0100 | [diff] [blame] | 111 | rev, path); |
Johan Herland | 48f7b98 | 2010-06-10 01:09:30 +0200 | [diff] [blame] | 112 | html(")\n"); |
Michael Krelin | d6b01da | 2007-07-21 19:51:47 +0200 | [diff] [blame] | 113 | |
Georg Lukas | ef07ccc | 2009-11-28 03:44:33 +0100 | [diff] [blame] | 114 | if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { |
Mark Lodato | e4ddc8f | 2010-09-04 11:30:18 -0400 | [diff] [blame] | 115 | htmlf("<div class='error'>blob size (%ldKB) exceeds display size limit (%dKB).</div>", |
Georg Lukas | ef07ccc | 2009-11-28 03:44:33 +0100 | [diff] [blame] | 116 | size / 1024, ctx.cfg.max_blob_size); |
| 117 | return; |
| 118 | } |
| 119 | |
Lars Hjemli | ae1d4d7 | 2009-01-31 17:45:48 +0100 | [diff] [blame] | 120 | if (buffer_is_binary(buf, size)) |
| 121 | print_binary_buffer(buf, size); |
| 122 | else |
Lars Hjemli | 46b7abe | 2009-07-31 16:55:27 +0200 | [diff] [blame] | 123 | print_text_buffer(basename, buf, size); |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
| 127 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
Lars Hjemli | 566f92b | 2008-07-21 10:10:48 +0200 | [diff] [blame] | 128 | const char *pathname, unsigned int mode, int stage, |
| 129 | void *cbdata) |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 130 | { |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 131 | struct walk_tree_context *walk_tree_ctx = cbdata; |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 132 | char *name; |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 133 | char *fullpath; |
Martin Szulecki | b4c3562 | 2009-08-07 14:06:02 +0200 | [diff] [blame] | 134 | char *class; |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame] | 135 | enum object_type type; |
Lars Hjemli | ded9393 | 2007-05-11 12:12:48 +0200 | [diff] [blame] | 136 | unsigned long size = 0; |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 137 | |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame] | 138 | name = xstrdup(pathname); |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 139 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
| 140 | ctx.qry.path ? "/" : "", name); |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 141 | |
Lars Hjemli | 08a8757 | 2008-05-20 22:32:22 +0200 | [diff] [blame] | 142 | if (!S_ISGITLINK(mode)) { |
| 143 | type = sha1_object_info(sha1, &size); |
| 144 | if (type == OBJ_BAD) { |
| 145 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
| 146 | name, |
| 147 | sha1_to_hex(sha1)); |
| 148 | return 0; |
| 149 | } |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 150 | } |
Lars Hjemli | 44947bf | 2007-06-17 01:23:08 +0200 | [diff] [blame] | 151 | |
Lars Hjemli | 426032f | 2007-06-17 13:17:00 +0200 | [diff] [blame] | 152 | html("<tr><td class='ls-mode'>"); |
Lars Hjemli | b1f9b9c | 2008-02-23 22:45:33 +0100 | [diff] [blame] | 153 | cgit_print_filemode(mode); |
Lars Hjemli | 426032f | 2007-06-17 13:17:00 +0200 | [diff] [blame] | 154 | html("</td><td>"); |
Jeffrey C. Ollie | e651cb0 | 2007-06-04 12:28:56 -0500 | [diff] [blame] | 155 | if (S_ISGITLINK(mode)) { |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 156 | cgit_submodule_link("ls-mod", fullpath, sha1_to_hex(sha1)); |
Lars Hjemli | 61c3ca9 | 2007-05-08 22:40:59 +0200 | [diff] [blame] | 157 | } else if (S_ISDIR(mode)) { |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 158 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 159 | walk_tree_ctx->curr_rev, fullpath); |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 160 | } else { |
Martin Szulecki | b4c3562 | 2009-08-07 14:06:02 +0200 | [diff] [blame] | 161 | class = strrchr(name, '.'); |
| 162 | if (class != NULL) { |
| 163 | class = fmt("ls-blob %s", class + 1); |
| 164 | } else |
| 165 | class = "ls-blob"; |
| 166 | cgit_tree_link(name, NULL, class, ctx.qry.head, |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 167 | walk_tree_ctx->curr_rev, fullpath); |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 168 | } |
Lars Hjemli | 426032f | 2007-06-17 13:17:00 +0200 | [diff] [blame] | 169 | htmlf("</td><td class='ls-size'>%li</td>", size); |
Lars Hjemli | 9fb53af | 2007-05-14 11:10:59 +0200 | [diff] [blame] | 170 | |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 171 | html("<td>"); |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 172 | cgit_log_link("log", NULL, "button", ctx.qry.head, |
| 173 | walk_tree_ctx->curr_rev, fullpath, 0, NULL, NULL, |
| 174 | ctx.qry.showmsg); |
Lars Hjemli | 837d464 | 2008-12-07 13:34:42 +0100 | [diff] [blame] | 175 | if (ctx.repo->max_stats) |
| 176 | cgit_stats_link("stats", NULL, "button", ctx.qry.head, |
| 177 | fullpath); |
Lars Hjemli | 6857bec | 2011-06-15 10:04:13 +0200 | [diff] [blame] | 178 | if (!S_ISGITLINK(mode)) |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 179 | cgit_plain_link("plain", NULL, "button", ctx.qry.head, |
| 180 | walk_tree_ctx->curr_rev, fullpath); |
Lars Hjemli | 48c487d | 2007-06-17 13:57:51 +0200 | [diff] [blame] | 181 | html("</td></tr>\n"); |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 182 | free(name); |
| 183 | return 0; |
| 184 | } |
| 185 | |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 186 | static void ls_head() |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 187 | { |
Lars Hjemli | 2915483 | 2007-11-11 13:04:28 +0100 | [diff] [blame] | 188 | html("<table summary='tree listing' class='list'>\n"); |
Lars Hjemli | 777faf7 | 2007-01-28 00:39:26 +0100 | [diff] [blame] | 189 | html("<tr class='nohover'>"); |
Lars Hjemli | a530428 | 2006-12-17 23:55:53 +0100 | [diff] [blame] | 190 | html("<th class='left'>Mode</th>"); |
| 191 | html("<th class='left'>Name</th>"); |
Lars Hjemli | 9a8f886 | 2006-12-16 00:19:56 +0100 | [diff] [blame] | 192 | html("<th class='right'>Size</th>"); |
Lars Hjemli | 9fb53af | 2007-05-14 11:10:59 +0200 | [diff] [blame] | 193 | html("<th/>"); |
Lars Hjemli | a530428 | 2006-12-17 23:55:53 +0100 | [diff] [blame] | 194 | html("</tr>\n"); |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static void ls_tail() |
| 198 | { |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 199 | html("</table>\n"); |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 202 | static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx) |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 203 | { |
| 204 | struct tree *tree; |
John Keeping | c1633c6 | 2013-03-02 12:32:11 +0000 | [diff] [blame] | 205 | struct pathspec paths = { |
| 206 | .nr = 0 |
| 207 | }; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 208 | |
| 209 | tree = parse_tree_indirect(sha1); |
| 210 | if (!tree) { |
| 211 | cgit_print_error(fmt("Not a tree object: %s", |
| 212 | sha1_to_hex(sha1))); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | ls_head(); |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 217 | read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx); |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 218 | ls_tail(); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
Lars Hjemli | 566f92b | 2008-07-21 10:10:48 +0200 | [diff] [blame] | 223 | const char *pathname, unsigned mode, int stage, |
| 224 | void *cbdata) |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 225 | { |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 226 | struct walk_tree_context *walk_tree_ctx = cbdata; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 227 | static char buffer[PATH_MAX]; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 228 | |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 229 | if (walk_tree_ctx->state == 0) { |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 230 | memcpy(buffer, base, baselen); |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 231 | strcpy(buffer + baselen, pathname); |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 232 | if (strcmp(walk_tree_ctx->match_path, buffer)) |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 233 | return READ_TREE_RECURSIVE; |
| 234 | |
| 235 | if (S_ISDIR(mode)) { |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 236 | walk_tree_ctx->state = 1; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 237 | ls_head(); |
| 238 | return READ_TREE_RECURSIVE; |
| 239 | } else { |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 240 | print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | } |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 244 | ls_item(sha1, base, baselen, pathname, mode, stage, walk_tree_ctx); |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | /* |
| 250 | * Show a tree or a blob |
| 251 | * rev: the commit pointing at the root tree object |
| 252 | * path: path to tree or blob |
| 253 | */ |
| 254 | void cgit_print_tree(const char *rev, char *path) |
| 255 | { |
| 256 | unsigned char sha1[20]; |
| 257 | struct commit *commit; |
John Keeping | c1633c6 | 2013-03-02 12:32:11 +0000 | [diff] [blame] | 258 | struct pathspec_item path_items = { |
| 259 | .match = path, |
| 260 | .len = path ? strlen(path) : 0 |
| 261 | }; |
| 262 | struct pathspec paths = { |
| 263 | .nr = path ? 1 : 0, |
| 264 | .items = &path_items |
| 265 | }; |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 266 | struct walk_tree_context walk_tree_ctx = { |
| 267 | .match_path = path, |
| 268 | .state = 0 |
| 269 | }; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 270 | |
| 271 | if (!rev) |
Lars Hjemli | d14d77f | 2008-02-16 11:53:40 +0100 | [diff] [blame] | 272 | rev = ctx.qry.head; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 273 | |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 274 | if (get_sha1(rev, sha1)) { |
| 275 | cgit_print_error(fmt("Invalid revision name: %s", rev)); |
| 276 | return; |
| 277 | } |
| 278 | commit = lookup_commit_reference(sha1); |
| 279 | if (!commit || parse_commit(commit)) { |
| 280 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
| 281 | return; |
| 282 | } |
| 283 | |
Lukas Fleischer | 985d6ca | 2013-03-04 13:25:36 +0100 | [diff] [blame^] | 284 | walk_tree_ctx.curr_rev = xstrdup(rev); |
| 285 | |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 286 | if (path == NULL) { |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 287 | ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx); |
Lukas Fleischer | 985d6ca | 2013-03-04 13:25:36 +0100 | [diff] [blame^] | 288 | goto cleanup; |
Lars Hjemli | ffc6973 | 2007-06-16 20:20:42 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Lukas Fleischer | 210a571 | 2013-03-03 17:22:30 +0100 | [diff] [blame] | 291 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); |
| 292 | if (walk_tree_ctx.state == 1) |
Lukas Fleischer | bfe5766 | 2013-03-03 16:55:21 +0100 | [diff] [blame] | 293 | ls_tail(); |
Lukas Fleischer | 985d6ca | 2013-03-04 13:25:36 +0100 | [diff] [blame^] | 294 | |
| 295 | cleanup: |
| 296 | free(walk_tree_ctx.curr_rev); |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 297 | } |