diff options
author | John Keeping | 2015-08-14 12:47:19 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2015-08-14 15:46:51 +0200 |
commit | 696a33b66f8638d5c3e0464d66760c6d60ff24a5 (patch) | |
tree | 8da0938fb4cc6ac6dc487dfc9a117cc1f910de3e | |
parent | summary: move layout into page function (diff) | |
download | cgit-696a33b66f8638d5c3e0464d66760c6d60ff24a5.tar.gz cgit-696a33b66f8638d5c3e0464d66760c6d60ff24a5.zip |
tag: move layout into page function
This also allows us to return proper HTTP error codes when something goes wrong. Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r-- | cmd.c | 2 | ||||
-rw-r--r-- | ui-tag.c | 13 |
2 files changed, 11 insertions, 4 deletions
diff --git a/cmd.c b/cmd.c index 928c8aa..54961d9 100644 --- a/cmd.c +++ b/cmd.c | |||
@@ -171,7 +171,7 @@ struct cgit_cmd *cgit_get_cmd(void) | |||
171 | def_cmd(snapshot, 1, 0, 0, 0), | 171 | def_cmd(snapshot, 1, 0, 0, 0), |
172 | def_cmd(stats, 1, 0, 1, 0), | 172 | def_cmd(stats, 1, 0, 1, 0), |
173 | def_cmd(summary, 1, 0, 0, 0), | 173 | def_cmd(summary, 1, 0, 0, 0), |
174 | def_cmd(tag, 1, 1, 0, 0), | 174 | def_cmd(tag, 1, 0, 0, 0), |
175 | def_cmd(tree, 1, 1, 1, 0), | 175 | def_cmd(tree, 1, 1, 1, 0), |
176 | }; | 176 | }; |
177 | int i; | 177 | int i; |
diff --git a/ui-tag.c b/ui-tag.c index c1d1738..0afc663 100644 --- a/ui-tag.c +++ b/ui-tag.c | |||
@@ -52,20 +52,24 @@ void cgit_print_tag(char *revname) | |||
52 | 52 | ||
53 | strbuf_addf(&fullref, "refs/tags/%s", revname); | 53 | strbuf_addf(&fullref, "refs/tags/%s", revname); |
54 | if (get_sha1(fullref.buf, sha1)) { | 54 | if (get_sha1(fullref.buf, sha1)) { |
55 | cgit_print_error("Bad tag reference: %s", revname); | 55 | cgit_print_error_page(404, "Not found", |
56 | "Bad tag reference: %s", revname); | ||
56 | goto cleanup; | 57 | goto cleanup; |
57 | } | 58 | } |
58 | obj = parse_object(sha1); | 59 | obj = parse_object(sha1); |
59 | if (!obj) { | 60 | if (!obj) { |
60 | cgit_print_error("Bad object id: %s", sha1_to_hex(sha1)); | 61 | cgit_print_error_page(500, "Internal server error", |
62 | "Bad object id: %s", sha1_to_hex(sha1)); | ||
61 | goto cleanup; | 63 | goto cleanup; |
62 | } | 64 | } |
63 | if (obj->type == OBJ_TAG) { | 65 | if (obj->type == OBJ_TAG) { |
64 | tag = lookup_tag(sha1); | 66 | tag = lookup_tag(sha1); |
65 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { | 67 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { |
66 | cgit_print_error("Bad tag object: %s", revname); | 68 | cgit_print_error_page(500, "Internal server error", |
69 | "Bad tag object: %s", revname); | ||
67 | goto cleanup; | 70 | goto cleanup; |
68 | } | 71 | } |
72 | cgit_print_layout_start(); | ||
69 | html("<table class='commit-info'>\n"); | 73 | html("<table class='commit-info'>\n"); |
70 | htmlf("<tr><td>tag name</td><td>"); | 74 | htmlf("<tr><td>tag name</td><td>"); |
71 | html_txt(revname); | 75 | html_txt(revname); |
@@ -93,7 +97,9 @@ void cgit_print_tag(char *revname) | |||
93 | print_download_links(revname); | 97 | print_download_links(revname); |
94 | html("</table>\n"); | 98 | html("</table>\n"); |
95 | print_tag_content(info->msg); | 99 | print_tag_content(info->msg); |
100 | cgit_print_layout_end(); | ||
96 | } else { | 101 | } else { |
102 | cgit_print_layout_start(); | ||
97 | html("<table class='commit-info'>\n"); | 103 | html("<table class='commit-info'>\n"); |
98 | htmlf("<tr><td>tag name</td><td>"); | 104 | htmlf("<tr><td>tag name</td><td>"); |
99 | html_txt(revname); | 105 | html_txt(revname); |
@@ -104,6 +110,7 @@ void cgit_print_tag(char *revname) | |||
104 | if (ctx.repo->snapshots) | 110 | if (ctx.repo->snapshots) |
105 | print_download_links(revname); | 111 | print_download_links(revname); |
106 | html("</table>\n"); | 112 | html("</table>\n"); |
113 | cgit_print_layout_end(); | ||
107 | } | 114 | } |
108 | 115 | ||
109 | cleanup: | 116 | cleanup: |