diff options
Diffstat (limited to 'ui-tree.c')
-rw-r--r-- | ui-tree.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -92,16 +92,19 @@ static void print_object(const unsigned char *sha1, char *path, const char *base | |||
92 | 92 | ||
93 | type = sha1_object_info(sha1, &size); | 93 | type = sha1_object_info(sha1, &size); |
94 | if (type == OBJ_BAD) { | 94 | if (type == OBJ_BAD) { |
95 | cgit_print_error("Bad object name: %s", sha1_to_hex(sha1)); | 95 | cgit_print_error_page(404, "Not found", |
96 | "Bad object name: %s", sha1_to_hex(sha1)); | ||
96 | return; | 97 | return; |
97 | } | 98 | } |
98 | 99 | ||
99 | buf = read_sha1_file(sha1, &type, &size); | 100 | buf = read_sha1_file(sha1, &type, &size); |
100 | if (!buf) { | 101 | if (!buf) { |
101 | cgit_print_error("Error reading object %s", sha1_to_hex(sha1)); | 102 | cgit_print_error_page(500, "Internal server error", |
103 | "Error reading object %s", sha1_to_hex(sha1)); | ||
102 | return; | 104 | return; |
103 | } | 105 | } |
104 | 106 | ||
107 | cgit_print_layout_start(); | ||
105 | htmlf("blob: %s (", sha1_to_hex(sha1)); | 108 | htmlf("blob: %s (", sha1_to_hex(sha1)); |
106 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, | 109 | cgit_plain_link("plain", NULL, NULL, ctx.qry.head, |
107 | rev, path); | 110 | rev, path); |
@@ -181,6 +184,7 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, | |||
181 | 184 | ||
182 | static void ls_head(void) | 185 | static void ls_head(void) |
183 | { | 186 | { |
187 | cgit_print_layout_start(); | ||
184 | html("<table summary='tree listing' class='list'>\n"); | 188 | html("<table summary='tree listing' class='list'>\n"); |
185 | html("<tr class='nohover'>"); | 189 | html("<tr class='nohover'>"); |
186 | html("<th class='left'>Mode</th>"); | 190 | html("<th class='left'>Mode</th>"); |
@@ -193,6 +197,7 @@ static void ls_head(void) | |||
193 | static void ls_tail(void) | 197 | static void ls_tail(void) |
194 | { | 198 | { |
195 | html("</table>\n"); | 199 | html("</table>\n"); |
200 | cgit_print_layout_end(); | ||
196 | } | 201 | } |
197 | 202 | ||
198 | static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx) | 203 | static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx) |
@@ -204,7 +209,8 @@ static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_cont | |||
204 | 209 | ||
205 | tree = parse_tree_indirect(sha1); | 210 | tree = parse_tree_indirect(sha1); |
206 | if (!tree) { | 211 | if (!tree) { |
207 | cgit_print_error("Not a tree object: %s", sha1_to_hex(sha1)); | 212 | cgit_print_error_page(404, "Not found", |
213 | "Not a tree object: %s", sha1_to_hex(sha1)); | ||
208 | return; | 214 | return; |
209 | } | 215 | } |
210 | 216 | ||
@@ -231,6 +237,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, | |||
231 | ls_head(); | 237 | ls_head(); |
232 | return READ_TREE_RECURSIVE; | 238 | return READ_TREE_RECURSIVE; |
233 | } else { | 239 | } else { |
240 | walk_tree_ctx->state = 2; | ||
234 | print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); | 241 | print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); |
235 | return 0; | 242 | return 0; |
236 | } | 243 | } |
@@ -265,12 +272,14 @@ void cgit_print_tree(const char *rev, char *path) | |||
265 | rev = ctx.qry.head; | 272 | rev = ctx.qry.head; |
266 | 273 | ||
267 | if (get_sha1(rev, sha1)) { | 274 | if (get_sha1(rev, sha1)) { |
268 | cgit_print_error("Invalid revision name: %s", rev); | 275 | cgit_print_error_page(404, "Not found", |
276 | "Invalid revision name: %s", rev); | ||
269 | return; | 277 | return; |
270 | } | 278 | } |
271 | commit = lookup_commit_reference(sha1); | 279 | commit = lookup_commit_reference(sha1); |
272 | if (!commit || parse_commit(commit)) { | 280 | if (!commit || parse_commit(commit)) { |
273 | cgit_print_error("Invalid commit reference: %s", rev); | 281 | cgit_print_error_page(404, "Not found", |
282 | "Invalid commit reference: %s", rev); | ||
274 | return; | 283 | return; |
275 | } | 284 | } |
276 | 285 | ||
@@ -284,6 +293,10 @@ void cgit_print_tree(const char *rev, char *path) | |||
284 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); | 293 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); |
285 | if (walk_tree_ctx.state == 1) | 294 | if (walk_tree_ctx.state == 1) |
286 | ls_tail(); | 295 | ls_tail(); |
296 | else if (walk_tree_ctx.state == 2) | ||
297 | cgit_print_layout_end(); | ||
298 | else | ||
299 | cgit_print_error_page(404, "Not found", "Path not found"); | ||
287 | 300 | ||
288 | cleanup: | 301 | cleanup: |
289 | free(walk_tree_ctx.curr_rev); | 302 | free(walk_tree_ctx.curr_rev); |