diff options
author | John Keeping | 2013-04-06 11:23:52 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2013-04-08 16:11:29 +0200 |
commit | ed5bd30ebe6921dd22948a3f33a314283f043606 (patch) | |
tree | 494f1ac8aae7c2147146fefc9aebcdb1bfa671c0 /cgit.c | |
parent | d2e20e38141c882e46eaa77f172fc2ae37a19d3b (diff) | |
download | cgit-ed5bd30ebe6921dd22948a3f33a314283f043606.tar.gz cgit-ed5bd30ebe6921dd22948a3f33a314283f043606.tar.bz2 cgit-ed5bd30ebe6921dd22948a3f33a314283f043606.zip |
Convert cgit_print_error to a variadic function
This removes many uses of "fmt" which uses a fixed size static pool of
fixed size buffers. Instead of relying on these, we now pass around
argument lists for as long as possible before using a strbuf to render
content of an arbitrary size.
Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'cgit.c')
-rw-r--r-- | cgit.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -459,7 +459,6 @@ static char *guess_defbranch(void) | |||
459 | 459 | ||
460 | static int prepare_repo_cmd(struct cgit_context *ctx) | 460 | static int prepare_repo_cmd(struct cgit_context *ctx) |
461 | { | 461 | { |
462 | char *tmp; | ||
463 | unsigned char sha1[20]; | 462 | unsigned char sha1[20]; |
464 | int nongit = 0; | 463 | int nongit = 0; |
465 | int rc; | 464 | int rc; |
@@ -467,17 +466,16 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
467 | setenv("GIT_DIR", ctx->repo->path, 1); | 466 | setenv("GIT_DIR", ctx->repo->path, 1); |
468 | setup_git_directory_gently(&nongit); | 467 | setup_git_directory_gently(&nongit); |
469 | if (nongit) { | 468 | if (nongit) { |
469 | const char *name = ctx->repo->name; | ||
470 | rc = errno; | 470 | rc = errno; |
471 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, | 471 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
472 | "config error"); | 472 | "config error"); |
473 | tmp = fmt("Failed to open %s: %s", | ||
474 | ctx->repo->name, | ||
475 | rc ? strerror(rc) : "Not a valid git repository"); | ||
476 | ctx->repo = NULL; | 473 | ctx->repo = NULL; |
477 | cgit_print_http_headers(ctx); | 474 | cgit_print_http_headers(ctx); |
478 | cgit_print_docstart(ctx); | 475 | cgit_print_docstart(ctx); |
479 | cgit_print_pageheader(ctx); | 476 | cgit_print_pageheader(ctx); |
480 | cgit_print_error(tmp); | 477 | cgit_print_error("Failed to open %s: %s", name, |
478 | rc ? strerror(rc) : "Not a valid git repository"); | ||
481 | cgit_print_docend(); | 479 | cgit_print_docend(); |
482 | return 1; | 480 | return 1; |
483 | } | 481 | } |
@@ -501,14 +499,14 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
501 | } | 499 | } |
502 | 500 | ||
503 | if (get_sha1(ctx->qry.head, sha1)) { | 501 | if (get_sha1(ctx->qry.head, sha1)) { |
504 | tmp = xstrdup(ctx->qry.head); | 502 | char *tmp = xstrdup(ctx->qry.head); |
505 | ctx->qry.head = ctx->repo->defbranch; | 503 | ctx->qry.head = ctx->repo->defbranch; |
506 | ctx->page.status = 404; | 504 | ctx->page.status = 404; |
507 | ctx->page.statusmsg = "Not found"; | 505 | ctx->page.statusmsg = "Not found"; |
508 | cgit_print_http_headers(ctx); | 506 | cgit_print_http_headers(ctx); |
509 | cgit_print_docstart(ctx); | 507 | cgit_print_docstart(ctx); |
510 | cgit_print_pageheader(ctx); | 508 | cgit_print_pageheader(ctx); |
511 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 509 | cgit_print_error("Invalid branch: %s", tmp); |
512 | cgit_print_docend(); | 510 | cgit_print_docend(); |
513 | return 1; | 511 | return 1; |
514 | } | 512 | } |
@@ -550,7 +548,7 @@ static void process_request(void *cbdata) | |||
550 | cgit_print_http_headers(ctx); | 548 | cgit_print_http_headers(ctx); |
551 | cgit_print_docstart(ctx); | 549 | cgit_print_docstart(ctx); |
552 | cgit_print_pageheader(ctx); | 550 | cgit_print_pageheader(ctx); |
553 | cgit_print_error(fmt("No repository selected")); | 551 | cgit_print_error("No repository selected"); |
554 | cgit_print_docend(); | 552 | cgit_print_docend(); |
555 | return; | 553 | return; |
556 | } | 554 | } |
@@ -862,7 +860,7 @@ int main(int argc, const char **argv) | |||
862 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, | 860 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
863 | ctx.qry.raw, ttl, process_request, &ctx); | 861 | ctx.qry.raw, ttl, process_request, &ctx); |
864 | if (err) | 862 | if (err) |
865 | cgit_print_error(fmt("Error processing page: %s (%d)", | 863 | cgit_print_error("Error processing page: %s (%d)", |
866 | strerror(err), err)); | 864 | strerror(err), err); |
867 | return err; | 865 | return err; |
868 | } | 866 | } |