From a360666df3cfcd1b384cd66b18803d72e3893b3d Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:24:34 +0100 Subject: [PATCH 01/16] ui-shared: show full date in tooltip if longer ago than max_relative Commit caed6cb (ui-shared: show absolute time in tooltip for relative dates, 2014-12-20) added a toolip when we show a relative time. However, in some cases we show a short date (that is, the date but not the time) if an event was sufficiently far in the past and that commit did not update that case to add the same tooltip. Signed-off-by: John Keeping --- ui-shared.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index bbb277a..36fcb21 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -644,7 +644,11 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format) secs = 0; if (secs > max_relative && max_relative >= 0) { + html(""); cgit_print_date(t, format, ctx.cfg.local_time); + html(""); return; } -- 2.50.1 From c543d7dbf6bf7c8be5af829bf1d3eab494856ee0 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 15:54:37 +0100 Subject: [PATCH 02/16] Makefile: make "git/config.mak.uname" inclusion optional If we haven't got a "git" directory, it should still be possible to run "make get-git", so we cannot include this file unconditionally. Signed-off-by: John Keeping --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 74061a3..a0a6615 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) #-include config.mak -include git/config.mak.uname +-include git/config.mak.uname # # Let the user override the above settings. # -- 2.50.1 From aa12084f9835783abbd1f1e4609f8de05e73cec4 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 14 Aug 2015 00:02:50 +0200 Subject: [PATCH 03/16] ui-patch: make sure to send http headers Requesting a text/plain patch with bad commit id made cgit send text without proper http headers. This results in "500 Internal Server Error" with "Premature end of script headers" in server logs. So print http headers before error message and return. Signed-off-by: Christian Hesse Reviewed-by: John Keeping --- ui-patch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui-patch.c b/ui-patch.c index 6ec89b4..57ca2f8 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -25,21 +25,25 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, new_rev = ctx.qry.head; if (get_sha1(new_rev, new_rev_sha1)) { + cgit_print_http_headers(); cgit_print_error("Bad object id: %s", new_rev); return; } commit = lookup_commit_reference(new_rev_sha1); if (!commit) { + cgit_print_http_headers(); cgit_print_error("Bad commit reference: %s", new_rev); return; } if (old_rev) { if (get_sha1(old_rev, old_rev_sha1)) { + cgit_print_http_headers(); cgit_print_error("Bad object id: %s", old_rev); return; } if (!lookup_commit_reference(old_rev_sha1)) { + cgit_print_http_headers(); cgit_print_error("Bad commit reference: %s", old_rev); return; } -- 2.50.1 From aec1204a54e3baa12c76db75c2f67696def05eb0 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:01 +0100 Subject: [PATCH 04/16] ui-shared: add cgit_print_error_page() function This will allow us to generate error responses with the correct HTTP response code without needing all of the layout boilerplate. Signed-off-by: John Keeping --- ui-shared.c | 14 ++++++++++++++ ui-shared.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 36fcb21..06dd0a8 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -788,6 +788,20 @@ void cgit_print_docend(void) html("\n\n"); } +void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) +{ + va_list ap; + ctx.page.status = code; + ctx.page.statusmsg = msg; + cgit_print_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); + va_start(ap, fmt); + cgit_vprint_error(fmt, ap); + va_end(ap); + cgit_print_docend(); +} + static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) { struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); diff --git a/ui-shared.h b/ui-shared.h index d8a3551..652685e 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -64,6 +64,8 @@ extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void); extern void cgit_print_docend(); +__attribute__((format (printf,3,4))) +extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); extern void cgit_print_snapshot_links(const char *repo, const char *head, -- 2.50.1 From e9b71ae6fe910573156c4632a314b7dbf84d7b64 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:02 +0100 Subject: [PATCH 05/16] cgit: use cgit_print_error_page() where appropriate These are more-or-less one-to-one translations but in the final hunk we gain an HTTP error code where we used to send "200 OK", which is an improvement. Signed-off-by: John Keeping --- cgit.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/cgit.c b/cgit.c index d84b4be..3a97563 100644 --- a/cgit.c +++ b/cgit.c @@ -614,13 +614,8 @@ static int prepare_repo_cmd(void) if (get_sha1(ctx.qry.head, sha1)) { char *tmp = xstrdup(ctx.qry.head); ctx.qry.head = ctx.repo->defbranch; - ctx.page.status = 404; - ctx.page.statusmsg = "Not found"; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - cgit_print_error("Invalid branch: %s", tmp); - cgit_print_docend(); + cgit_print_error_page(404, "Not found", + "Invalid branch: %s", tmp); free(tmp); return 1; } @@ -713,18 +708,13 @@ static void process_request(void) cmd = cgit_get_cmd(); if (!cmd) { ctx.page.title = "cgit error"; - ctx.page.status = 404; - ctx.page.statusmsg = "Not found"; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - cgit_print_error("Invalid request"); - cgit_print_docend(); + cgit_print_error_page(404, "Not found", "Invalid request"); return; } if (!ctx.cfg.enable_http_clone && cmd->is_clone) { - html_status(404, "Not found", 0); + ctx.page.title = "cgit error"; + cgit_print_error_page(404, "Not found", "Invalid request"); return; } @@ -735,11 +725,8 @@ static void process_request(void) ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL; if (cmd->want_repo && !ctx.repo) { - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - cgit_print_error("No repository selected"); - cgit_print_docend(); + cgit_print_error_page(400, "Bad request", + "No repository selected"); return; } -- 2.50.1 From 329381dfe45d37cb94847ee92ebe58f2d6c02a9d Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:03 +0100 Subject: [PATCH 06/16] clone: use cgit_print_error_page() instead of html_status() This provides a formatted error response rather than a simple HTTP error. Signed-off-by: John Keeping --- ui-clone.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui-clone.c b/ui-clone.c index e4ddd34..f7b0b04 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -57,13 +57,13 @@ static void send_file(const char *path) if (stat(path, &st)) { switch (errno) { case ENOENT: - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); break; case EACCES: - html_status(403, "Forbidden", 0); + cgit_print_error_page(403, "Forbidden", "Forbidden"); break; default: - html_status(400, "Bad request", 0); + cgit_print_error_page(400, "Bad request", "Bad request"); } return; } @@ -78,7 +78,7 @@ static void send_file(const char *path) void cgit_clone_info(void) { if (!ctx.qry.path || strcmp(ctx.qry.path, "refs")) { - html_status(400, "Bad request", 0); + cgit_print_error_page(400, "Bad request", "Bad request"); return; } @@ -91,7 +91,7 @@ void cgit_clone_info(void) void cgit_clone_objects(void) { if (!ctx.qry.path) { - html_status(400, "Bad request", 0); + cgit_print_error_page(400, "Bad request", "Bad request"); return; } -- 2.50.1 From 2b3e76a9f95c50f55be70dbb1cfa029f5165a535 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:04 +0100 Subject: [PATCH 07/16] plain: use cgit_print_error_page() instead of html_status() This provides a formatted error response rather than a simple HTTP error. Signed-off-by: John Keeping --- ui-plain.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui-plain.c b/ui-plain.c index 3a2cb47..0daa7bf 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -66,13 +66,13 @@ static int print_object(const unsigned char *sha1, const char *path) type = sha1_object_info(sha1, &size); if (type == OBJ_BAD) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return 0; } buf = read_sha1_file(sha1, &type, &size); if (!buf) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return 0; } ctx.page.mimetype = NULL; @@ -225,12 +225,12 @@ void cgit_print_plain(void) rev = ctx.qry.head; if (get_sha1(rev, sha1)) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return; } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return; } if (!path_items.match) { @@ -243,7 +243,7 @@ void cgit_print_plain(void) walk_tree_ctx.match_baselen = basedir_len(path_items.match); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) print_dir_tail(); } -- 2.50.1 From 048f195eaf2fedb56987f0c8c89b9fd46375aa87 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:05 +0100 Subject: [PATCH 08/16] snapshot: use cgit_print_error_page() instead of html_status() This provides a formatted error response rather than a simple HTTP error. Signed-off-by: John Keeping --- ui-snapshot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index cb34f4b..bf4bcd7 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -213,7 +213,7 @@ void cgit_print_snapshot(const char *head, const char *hex, if (!hex && dwim) { hex = get_ref_from_filename(ctx.repo->url, filename, f); if (hex == NULL) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return; } prefix = xstrdup(filename); -- 2.50.1 From 9a06211daacd2fff14c6211bfc8bad856694f0f9 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:06 +0100 Subject: [PATCH 09/16] blob: use cgit_print_error_page() to add HTTP headers This is a bugfix as well as an improvement to the HTTP status code handling since previously we would not print HTTP headers on any of these code paths. Signed-off-by: John Keeping --- ui-blob.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ui-blob.c b/ui-blob.c index 388a017..b333f86 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -126,12 +126,14 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if (hex) { if (get_sha1_hex(hex, sha1)) { - cgit_print_error("Bad hex value: %s", hex); + cgit_print_error_page(400, "Bad request", + "Bad hex value: %s", hex); return; } } else { if (get_sha1(head, sha1)) { - cgit_print_error("Bad ref: %s", head); + cgit_print_error_page(404, "Not found", + "Bad ref: %s", head); return; } } @@ -145,13 +147,15 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl } if (type == OBJ_BAD) { - cgit_print_error("Bad object name: %s", hex); + cgit_print_error_page(404, "Not found", + "Bad object name: %s", hex); return; } buf = read_sha1_file(sha1, &type, &size); if (!buf) { - cgit_print_error("Error reading object %s", hex); + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", hex); return; } -- 2.50.1 From e3e41e5125b1ce270b5afb42beb83e14c0f350cb Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:07 +0100 Subject: [PATCH 10/16] patch: use cgit_print_error_page() for HTTP status codes Signed-off-by: John Keeping --- ui-patch.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ui-patch.c b/ui-patch.c index 57ca2f8..430231e 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -25,26 +25,26 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, new_rev = ctx.qry.head; if (get_sha1(new_rev, new_rev_sha1)) { - cgit_print_http_headers(); - cgit_print_error("Bad object id: %s", new_rev); + cgit_print_error_page(404, "Not found", + "Bad object id: %s", new_rev); return; } commit = lookup_commit_reference(new_rev_sha1); if (!commit) { - cgit_print_http_headers(); - cgit_print_error("Bad commit reference: %s", new_rev); + cgit_print_error_page(404, "Not found", + "Bad commit reference: %s", new_rev); return; } if (old_rev) { if (get_sha1(old_rev, old_rev_sha1)) { - cgit_print_http_headers(); - cgit_print_error("Bad object id: %s", old_rev); + cgit_print_error_page(404, "Not found", + "Bad object id: %s", old_rev); return; } if (!lookup_commit_reference(old_rev_sha1)) { - cgit_print_http_headers(); - cgit_print_error("Bad commit reference: %s", old_rev); + cgit_print_error_page(404, "Not found", + "Bad commit reference: %s", old_rev); return; } } else if (commit->parents && commit->parents->item) { -- 2.50.1 From 58e827cbd9811500f72bf25b1db569b208661618 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:08 +0100 Subject: [PATCH 11/16] snapshot: use cgit_print_error_page() for HTTP status codes This is a bugfix as well as an improvement to the HTTP status code handling since previously we would not print HTTP headers on any of these code paths. Signed-off-by: John Keeping --- ui-snapshot.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index bf4bcd7..9bcf13d 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -112,11 +112,13 @@ static int make_snapshot(const struct cgit_snapshot_format *format, unsigned char sha1[20]; if (get_sha1(hex, sha1)) { - cgit_print_error("Bad object id: %s", hex); + cgit_print_error_page(404, "Not found", + "Bad object id: %s", hex); return 1; } if (!lookup_commit_reference(sha1)) { - cgit_print_error("Not a commit reference: %s", hex); + cgit_print_error_page(400, "Bad request", + "Not a commit reference: %s", hex); return 1; } ctx.page.etag = sha1_to_hex(sha1); -- 2.50.1 From fd00e71ab7cf1eabd8d1fc2e5980055350849034 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:09 +0100 Subject: [PATCH 12/16] snapshot: don't reimplement cgit_print_error_page() cgit_print_error_page() has the advantage that it sets a suitable HTTP status code for the response. Note that setting "mimetype" is redundant here since it cannot have changed since being initialized in cgit.c::prepare_context(), so we do not need to worry that cgit_print_error_page() does not set it. Signed-off-by: John Keeping --- ui-snapshot.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index 9bcf13d..f68e877 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -180,21 +180,6 @@ out: return result ? strbuf_detach(&snapshot, NULL) : NULL; } -__attribute__((format (printf, 1, 2))) -static void show_error(char *fmt, ...) -{ - va_list ap; - - ctx.page.mimetype = "text/html"; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - va_start(ap, fmt); - cgit_vprint_error(fmt, ap); - va_end(ap); - cgit_print_docend(); -} - void cgit_print_snapshot(const char *head, const char *hex, const char *filename, int dwim) { @@ -202,13 +187,15 @@ void cgit_print_snapshot(const char *head, const char *hex, char *prefix = NULL; if (!filename) { - show_error("No snapshot name specified"); + cgit_print_error_page(400, "Bad request", + "No snapshot name specified"); return; } f = get_format(filename); if (!f) { - show_error("Unsupported snapshot format: %s", filename); + cgit_print_error_page(400, "Bad request", + "Unsupported snapshot format: %s", filename); return; } -- 2.50.1 From fb2c71fad23f4f13f56f74a8b79907805ab1b772 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:10 +0100 Subject: [PATCH 13/16] html: remove html_status() This is now unused. Signed-off-by: John Keeping --- html.c | 7 ------- html.h | 1 - 2 files changed, 8 deletions(-) diff --git a/html.c b/html.c index a47cff0..959148c 100644 --- a/html.c +++ b/html.c @@ -121,13 +121,6 @@ void html_vtxtf(const char *format, va_list ap) strbuf_release(&buf); } -void html_status(int code, const char *msg, int more_headers) -{ - htmlf("Status: %d %s\n", code, msg); - if (!more_headers) - html("\n"); -} - void html_txt(const char *txt) { const char *t = txt; diff --git a/html.h b/html.h index be3b311..c554763 100644 --- a/html.h +++ b/html.h @@ -18,7 +18,6 @@ extern void html_vtxtf(const char *format, va_list ap); __attribute__((format (printf,1,2))) extern void html_attrf(const char *format,...); -extern void html_status(int code, const char *msg, int more_headers); extern void html_txt(const char *txt); extern void html_ntxt(int len, const char *txt); extern void html_attr(const char *txt); -- 2.50.1 From 764987980ec0e806205b8e075feafd4e010dcbd9 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:11 +0100 Subject: [PATCH 14/16] ui-shared: add cgit_print_layout_{start,end}() These will avoid needing to call three functions to start page layout in subsequent patches when we move the layout setup into each individual page. Signed-off-by: John Keeping --- ui-shared.c | 12 ++++++++++++ ui-shared.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 06dd0a8..de06256 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -802,6 +802,18 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) cgit_print_docend(); } +void cgit_print_layout_start(void) +{ + cgit_print_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); +} + +void cgit_print_layout_end(void) +{ + cgit_print_docend(); +} + static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) { struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); diff --git a/ui-shared.h b/ui-shared.h index 652685e..246678b 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -54,6 +54,9 @@ extern void cgit_object_link(struct object *obj); extern void cgit_submodule_link(const char *class, char *path, const char *rev); +extern void cgit_print_layout_start(void); +extern void cgit_print_layout_end(void); + __attribute__((format (printf,1,2))) extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) -- 2.50.1 From 51d9176e4bb5c619481355c6b895c6dec30c4f82 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:12 +0100 Subject: [PATCH 15/16] about: move layout into page functions Signed-off-by: John Keeping --- cmd.c | 2 +- ui-repolist.c | 5 ++++- ui-summary.c | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd.c b/cmd.c index 315edc3..616890c 100644 --- a/cmd.c +++ b/cmd.c @@ -155,7 +155,7 @@ struct cgit_cmd *cgit_get_cmd(void) static struct cgit_cmd cmds[] = { def_cmd(HEAD, 1, 0, 0, 1), def_cmd(atom, 1, 0, 0, 0), - def_cmp(about, 0, 1, 0, 0), + def_cmp(about, 0, 0, 0, 0), def_cmd(blob, 1, 0, 0, 0), def_cmd(commit, 1, 1, 1, 0), def_cmd(diff, 1, 1, 1, 0), diff --git a/ui-repolist.c b/ui-repolist.c index 43253ed..ac1b3e3 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -345,9 +345,12 @@ void cgit_print_repolist(void) void cgit_print_site_readme(void) { + cgit_print_layout_start(); if (!ctx.cfg.root_readme) - return; + goto done; cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); html_include(ctx.cfg.root_readme); cgit_close_filter(ctx.cfg.about_filter); +done: + cgit_print_layout_end(); } diff --git a/ui-summary.c b/ui-summary.c index a5c7078..cd1fef5 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -101,8 +101,9 @@ void cgit_print_repo_readme(char *path) char *filename, *ref; int free_filename = 0; + cgit_print_layout_start(); if (ctx.repo->readme.nr == 0) - return; + goto done; filename = ctx.repo->readme.items[0].string; ref = ctx.repo->readme.items[0].util; @@ -111,7 +112,7 @@ void cgit_print_repo_readme(char *path) free_filename = 1; filename = append_readme_path(filename, ref, path); if (!filename) - return; + goto done; } /* Print the calculated readme, either from the git repo or from the @@ -128,4 +129,7 @@ void cgit_print_repo_readme(char *path) html(""); if (free_filename) free(filename); + +done: + cgit_print_layout_end(); } -- 2.50.1 From c53a15c77a6763b4d6fefb033923ba7493b884a2 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:13 +0100 Subject: [PATCH 16/16] commit: move layout into page function This allows us to return a proper HTTP status code when an object is not found by switching from cgit_print_error() to cgit_print_error_page(). Signed-off-by: John Keeping --- cmd.c | 2 +- ui-commit.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd.c b/cmd.c index 616890c..1b42a47 100644 --- a/cmd.c +++ b/cmd.c @@ -157,7 +157,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(atom, 1, 0, 0, 0), def_cmp(about, 0, 0, 0, 0), def_cmd(blob, 1, 0, 0, 0), - def_cmd(commit, 1, 1, 1, 0), + def_cmd(commit, 1, 0, 1, 0), def_cmd(diff, 1, 1, 1, 0), def_cmd(info, 1, 0, 0, 1), def_cmd(log, 1, 1, 1, 0), diff --git a/ui-commit.c b/ui-commit.c index d5a888d..2bca7a0 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -27,12 +27,14 @@ void cgit_print_commit(char *hex, const char *prefix) hex = ctx.qry.head; if (get_sha1(hex, sha1)) { - cgit_print_error("Bad object id: %s", hex); + cgit_print_error_page(400, "Bad request", + "Bad object id: %s", hex); return; } commit = lookup_commit_reference(sha1); if (!commit) { - cgit_print_error("Bad commit reference: %s", hex); + cgit_print_error_page(404, "Not found", + "Bad commit reference: %s", hex); return; } info = cgit_parse_commit(commit); @@ -41,6 +43,7 @@ void cgit_print_commit(char *hex, const char *prefix) load_ref_decorations(DECORATE_FULL_REFS); + cgit_print_layout_start(); cgit_print_diff_ctrls(); html("\n"); html("
author"); @@ -139,4 +142,5 @@ void cgit_print_commit(char *hex, const char *prefix) } strbuf_release(¬es); cgit_free_commitinfo(info); + cgit_print_layout_end(); } -- 2.50.1