aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cgit.c18
-rw-r--r--ui-blob.c8
-rw-r--r--ui-commit.c4
-rw-r--r--ui-diff.c8
-rw-r--r--ui-patch.c4
-rw-r--r--ui-shared.c15
-rw-r--r--ui-shared.h5
-rw-r--r--ui-snapshot.c16
-rw-r--r--ui-stats.c5
-rw-r--r--ui-tag.c6
-rw-r--r--ui-tree.c13
11 files changed, 57 insertions, 45 deletions
diff --git a/cgit.c b/cgit.c
index 6f75db1..4e51283 100644
--- a/cgit.c
+++ b/cgit.c
@@ -459,7 +459,6 @@ static char *guess_defbranch(void)
459 459
460static int prepare_repo_cmd(struct cgit_context *ctx) 460static 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}
diff --git a/ui-blob.c b/ui-blob.c
index 1da43c8..8f6989f 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -94,12 +94,12 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
94 94
95 if (hex) { 95 if (hex) {
96 if (get_sha1_hex(hex, sha1)) { 96 if (get_sha1_hex(hex, sha1)) {
97 cgit_print_error(fmt("Bad hex value: %s", hex)); 97 cgit_print_error("Bad hex value: %s", hex);
98 return; 98 return;
99 } 99 }
100 } else { 100 } else {
101 if (get_sha1(head, sha1)) { 101 if (get_sha1(head, sha1)) {
102 cgit_print_error(fmt("Bad ref: %s", head)); 102 cgit_print_error("Bad ref: %s", head);
103 return; 103 return;
104 } 104 }
105 } 105 }
@@ -113,13 +113,13 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
113 } 113 }
114 114
115 if (type == OBJ_BAD) { 115 if (type == OBJ_BAD) {
116 cgit_print_error(fmt("Bad object name: %s", hex)); 116 cgit_print_error("Bad object name: %s", hex);
117 return; 117 return;
118 } 118 }
119 119
120 buf = read_sha1_file(sha1, &type, &size); 120 buf = read_sha1_file(sha1, &type, &size);
121 if (!buf) { 121 if (!buf) {
122 cgit_print_error(fmt("Error reading object %s", hex)); 122 cgit_print_error("Error reading object %s", hex);
123 return; 123 return;
124 } 124 }
125 125
diff --git a/ui-commit.c b/ui-commit.c
index 8310ce6..6b41017 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -27,12 +27,12 @@ void cgit_print_commit(char *hex, const char *prefix)
27 hex = ctx.qry.head; 27 hex = ctx.qry.head;
28 28
29 if (get_sha1(hex, sha1)) { 29 if (get_sha1(hex, sha1)) {
30 cgit_print_error(fmt("Bad object id: %s", hex)); 30 cgit_print_error("Bad object id: %s", hex);
31 return; 31 return;
32 } 32 }
33 commit = lookup_commit_reference(sha1); 33 commit = lookup_commit_reference(sha1);
34 if (!commit) { 34 if (!commit) {
35 cgit_print_error(fmt("Bad commit reference: %s", hex)); 35 cgit_print_error("Bad commit reference: %s", hex);
36 return; 36 return;
37 } 37 }
38 info = cgit_parse_commit(commit); 38 info = cgit_parse_commit(commit);
diff --git a/ui-diff.c b/ui-diff.c
index 1115518..8b38209 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -369,12 +369,12 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
369 get_sha1(new_rev, new_rev_sha1); 369 get_sha1(new_rev, new_rev_sha1);
370 type = sha1_object_info(new_rev_sha1, &size); 370 type = sha1_object_info(new_rev_sha1, &size);
371 if (type == OBJ_BAD) { 371 if (type == OBJ_BAD) {
372 cgit_print_error(fmt("Bad object name: %s", new_rev)); 372 cgit_print_error("Bad object name: %s", new_rev);
373 return; 373 return;
374 } 374 }
375 commit = lookup_commit_reference(new_rev_sha1); 375 commit = lookup_commit_reference(new_rev_sha1);
376 if (!commit || parse_commit(commit)) { 376 if (!commit || parse_commit(commit)) {
377 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); 377 cgit_print_error("Bad commit: %s", sha1_to_hex(new_rev_sha1));
378 return; 378 return;
379 } 379 }
380 380
@@ -388,12 +388,12 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
388 if (!is_null_sha1(old_rev_sha1)) { 388 if (!is_null_sha1(old_rev_sha1)) {
389 type = sha1_object_info(old_rev_sha1, &size); 389 type = sha1_object_info(old_rev_sha1, &size);
390 if (type == OBJ_BAD) { 390 if (type == OBJ_BAD) {
391 cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); 391 cgit_print_error("Bad object name: %s", sha1_to_hex(old_rev_sha1));
392 return; 392 return;
393 } 393 }
394 commit2 = lookup_commit_reference(old_rev_sha1); 394 commit2 = lookup_commit_reference(old_rev_sha1);
395 if (!commit2 || parse_commit(commit2)) { 395 if (!commit2 || parse_commit(commit2)) {
396 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); 396 cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1));
397 return; 397 return;
398 } 398 }
399 } 399 }
diff --git a/ui-patch.c b/ui-patch.c
index 66def3c..fbb92cc 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -94,12 +94,12 @@ void cgit_print_patch(char *hex, const char *prefix)
94 hex = ctx.qry.head; 94 hex = ctx.qry.head;
95 95
96 if (get_sha1(hex, sha1)) { 96 if (get_sha1(hex, sha1)) {
97 cgit_print_error(fmt("Bad object id: %s", hex)); 97 cgit_print_error("Bad object id: %s", hex);
98 return; 98 return;
99 } 99 }
100 commit = lookup_commit_reference(sha1); 100 commit = lookup_commit_reference(sha1);
101 if (!commit) { 101 if (!commit) {
102 cgit_print_error(fmt("Bad commit reference: %s", hex)); 102 cgit_print_error("Bad commit reference: %s", hex);
103 return; 103 return;
104 } 104 }
105 info = cgit_parse_commit(commit); 105 info = cgit_parse_commit(commit);
diff --git a/ui-shared.c b/ui-shared.c
index c1f3c20..b93b77a 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -28,10 +28,21 @@ static char *http_date(time_t t)
28 tm->tm_hour, tm->tm_min, tm->tm_sec); 28 tm->tm_hour, tm->tm_min, tm->tm_sec);
29} 29}
30 30
31void cgit_print_error(const char *msg) 31void cgit_print_error(const char *fmt, ...)
32{ 32{
33 va_list ap;
34 va_start(ap, fmt);
35 cgit_vprint_error(fmt, ap);
36 va_end(ap);
37}
38
39void cgit_vprint_error(const char *fmt, va_list ap)
40{
41 va_list cp;
33 html("<div class='error'>"); 42 html("<div class='error'>");
34 html_txt(msg); 43 va_copy(cp, ap);
44 html_vtxtf(fmt, cp);
45 va_end(cp);
35 html("</div>\n"); 46 html("</div>\n");
36} 47}
37 48
diff --git a/ui-shared.h b/ui-shared.h
index 5f8b629..5987e77 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -52,7 +52,10 @@ extern void cgit_object_link(struct object *obj);
52extern void cgit_submodule_link(const char *class, char *path, 52extern void cgit_submodule_link(const char *class, char *path,
53 const char *rev); 53 const char *rev);
54 54
55extern void cgit_print_error(const char *msg); 55__attribute__((format (printf,1,2)))
56extern void cgit_print_error(const char *fmt, ...);
57__attribute__((format (printf,1,0)))
58extern void cgit_vprint_error(const char *fmt, va_list ap);
56extern void cgit_print_date(time_t secs, const char *format, int local_time); 59extern void cgit_print_date(time_t secs, const char *format, int local_time);
57extern void cgit_print_age(time_t t, time_t max_relative, const char *format); 60extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
58extern void cgit_print_http_headers(struct cgit_context *ctx); 61extern void cgit_print_http_headers(struct cgit_context *ctx);
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 9be5dbe..a47884e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -100,11 +100,11 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
100 unsigned char sha1[20]; 100 unsigned char sha1[20];
101 101
102 if (get_sha1(hex, sha1)) { 102 if (get_sha1(hex, sha1)) {
103 cgit_print_error(fmt("Bad object id: %s", hex)); 103 cgit_print_error("Bad object id: %s", hex);
104 return 1; 104 return 1;
105