diff options
-rw-r--r-- | cgit.c | 18 | ||||
-rw-r--r-- | ui-blob.c | 8 | ||||
-rw-r--r-- | ui-commit.c | 4 | ||||
-rw-r--r-- | ui-diff.c | 8 | ||||
-rw-r--r-- | ui-patch.c | 4 | ||||
-rw-r--r-- | ui-shared.c | 15 | ||||
-rw-r--r-- | ui-shared.h | 5 | ||||
-rw-r--r-- | ui-snapshot.c | 16 | ||||
-rw-r--r-- | ui-stats.c | 5 | ||||
-rw-r--r-- | ui-tag.c | 6 | ||||
-rw-r--r-- | ui-tree.c | 13 |
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 | ||
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 | } |
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 | ||
31 | void cgit_print_error(const char *msg) | 31 | void 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 | |||
39 | void 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); | |||
52 | extern void cgit_submodule_link(const char *class, char *path, | 52 | extern void cgit_submodule_link(const char *class, char *path, |
53 | const char *rev); | 53 | const char *rev); |
54 | 54 | ||
55 | extern void cgit_print_error(const char *msg); | 55 | __attribute__((format (printf,1,2))) |
56 | extern void cgit_print_error(const char *fmt, ...); | ||
57 | __attribute__((format (printf,1,0))) | ||
58 | extern void cgit_vprint_error(const char *fmt, va_list ap); | ||
56 | extern void cgit_print_date(time_t secs, const char *format, int local_time); | 59 | extern void cgit_print_date(time_t secs, const char *format, int local_time); |
57 | extern void cgit_print_age(time_t t, time_t max_relative, const char *format); | 60 | extern void cgit_print_age(time_t t, time_t max_relative, const char *format); |
58 | extern void cgit_print_http_headers(struct cgit_context *ctx); | 61 | extern 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 | } | 105 | } |
106 | if (!lookup_commit_reference(sha1)) { | 106 | if (!lookup_commit_reference(sha1)) { |
107 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 107 | cgit_print_error("Not a commit reference: %s", hex); |
108 | return 1; | 108 | return 1; |
109 | } | 109 | } |
110 | ctx.page.mimetype = xstrdup(format->mimetype); | 110 | ctx.page.mimetype = xstrdup(format->mimetype); |
@@ -154,13 +154,18 @@ static const char *get_ref_from_filename(const char *url, const char *filename, | |||
154 | return NULL; | 154 | return NULL; |
155 | } | 155 | } |
156 | 156 | ||
157 | static void show_error(char *msg) | 157 | __attribute__((format (printf, 1, 2))) |
158 | static void show_error(char *fmt, ...) | ||
158 | { | 159 | { |
160 | va_list ap; | ||
161 | |||
159 | ctx.page.mimetype = "text/html"; | 162 | ctx.page.mimetype = "text/html"; |
160 | cgit_print_http_headers(&ctx); | 163 | cgit_print_http_headers(&ctx); |
161 | cgit_print_docstart(&ctx); | 164 | cgit_print_docstart(&ctx); |
162 | cgit_print_pageheader(&ctx); | 165 | cgit_print_pageheader(&ctx); |
163 | cgit_print_error(msg); | 166 | va_start(ap, fmt); |
167 | cgit_vprint_error(fmt, ap); | ||
168 | va_end(ap); | ||
164 | cgit_print_docend(); | 169 | cgit_print_docend(); |
165 | } | 170 | } |
166 | 171 | ||
@@ -177,8 +182,7 @@ void cgit_print_snapshot(const char *head, const char *hex, | |||
177 | 182 | ||
178 | f = get_format(filename); | 183 | f = get_format(filename); |
179 | if (!f) { | 184 | if (!f) { |
180 | show_error(xstrdup(fmt("Unsupported snapshot format: %s", | 185 | show_error("Unsupported snapshot format: %s", filename); |
181 | filename))); | ||
182 | return; | 186 | return; |
183 | } | 187 | } |
184 | 188 | ||
diff --git a/ui-stats.c b/ui-stats.c index 52e9b91..28b794f 100644 --- a/ui-stats.c +++ b/ui-stats.c | |||
@@ -374,12 +374,11 @@ void cgit_show_stats(struct cgit_context *ctx) | |||
374 | 374 | ||
375 | i = cgit_find_stats_period(code, &period); | 375 | i = cgit_find_stats_period(code, &period); |
376 | if (!i) { | 376 | if (!i) { |
377 | cgit_print_error(fmt("Unknown statistics type: %c", code[0])); | 377 | cgit_print_error("Unknown statistics type: %c", code[0]); |
378 | return; | 378 | return; |
379 | } | 379 | } |
380 | if (i > ctx->repo->max_stats) { | 380 | if (i > ctx->repo->max_stats) { |
381 | cgit_print_error(fmt("Statistics type disabled: %s", | 381 | cgit_print_error("Statistics type disabled: %s", period->name); |
382 | period->name)); | ||
383 | return; | 382 | return; |
384 | } | 383 | } |
385 | authors = collect_stats(ctx, period); | 384 | authors = collect_stats(ctx, period); |
diff --git a/ui-tag.c b/ui-tag.c index 5a22696..397e15b 100644 --- a/ui-tag.c +++ b/ui-tag.c | |||
@@ -50,18 +50,18 @@ void cgit_print_tag(char *revname) | |||
50 | revname = ctx.qry.head; | 50 | revname = ctx.qry.head; |
51 | 51 | ||
52 | if (get_sha1(fmt("refs/tags/%s", revname), sha1)) { | 52 | if (get_sha1(fmt("refs/tags/%s", revname), sha1)) { |
53 | cgit_print_error(fmt("Bad tag reference: %s", revname)); | 53 | cgit_print_error("Bad tag reference: %s", revname); |
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | obj = parse_object(sha1); | 56 | obj = parse_object(sha1); |
57 | if (!obj) { | 57 | if (!obj) { |
58 | cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1))); | 58 | cgit_print_error("Bad object id: %s", sha1_to_hex(sha1)); |
59 | return; | 59 | return; |
60 | } | 60 | } |
61 | if (obj->type == OBJ_TAG) { | 61 | if (obj->type == OBJ_TAG) { |
62 | tag = lookup_tag(sha1); | 62 | tag = lookup_tag(sha1); |
63 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { | 63 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { |
64 | cgit_print_error(fmt("Bad tag object: %s", revname)); | 64 | cgit_print_error("Bad tag object: %s", revname); |
65 | return; | 65 | return; |
66 | } | 66 | } |
67 | html("<table class='commit-info'>\n"); | 67 | html("<table class='commit-info'>\n"); |
diff --git a/ui-tree.c b/ui-tree.c index d713553..aebe145 100644 --- a/ui-tree.c +++ b/ui-tree.c | |||
@@ -95,15 +95,13 @@ static void print_object(const unsigned char *sha1, char *path, const char *base | |||
95 | 95 | ||
96 | type = sha1_object_info(sha1, &size); | 96 | type = sha1_object_info(sha1, &size); |
97 | if (type == OBJ_BAD) { | 97 | if (type == OBJ_BAD) { |
98 | cgit_print_error(fmt("Bad object name: %s", | 98 | cgit_print_error("Bad object name: %s", sha1_to_hex(sha1)); |
99 | sha1_to_hex(sha1))); | ||
100 | return; | 99 | return; |
101 | } | 100 | } |
102 | 101 | ||
103 | buf = read_sha1_file(sha1, &type, &size); | 102 | buf = read_sha1_file(sha1, &type, &size); |
104 | if (!buf) { | 103 | if (!buf) { |
105 | cgit_print_error(fmt("Error reading object %s", | 104 | cgit_print_error("Error reading object %s", sha1_to_hex(sha1)); |
106 | sha1_to_hex(sha1))); | ||
107 | return; | 105 | return; |
108 | } | 106 | } |
109 | 107 | ||
@@ -209,8 +207,7 @@ static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_cont | |||
209 | 207 | ||
210 | tree = parse_tree_indirect(sha1); | 208 | tree = parse_tree_indirect(sha1); |
211 | if (!tree) { | 209 | if (!tree) { |
212 | cgit_print_error(fmt("Not a tree object: %s", | 210 | cgit_print_error("Not a tree object: %s", sha1_to_hex(sha1)); |
213 | sha1_to_hex(sha1))); | ||
214 | return; | 211 | return; |
215 | } | 212 | } |
216 | 213 | ||
@@ -273,12 +270,12 @@ void cgit_print_tree(const char *rev, char *path) | |||
273 | rev = ctx.qry.head; | 270 | rev = ctx.qry.head; |
274 | 271 | ||
275 | if (get_sha1(rev, sha1)) { | 272 | if (get_sha1(rev, sha1)) { |
276 | cgit_print_error(fmt("Invalid revision name: %s", rev)); | 273 | cgit_print_error("Invalid revision name: %s", rev); |
277 | return; | 274 | return; |
278 | } | 275 | } |
279 | commit = lookup_commit_reference(sha1); | 276 | commit = lookup_commit_reference(sha1); |
280 | if (!commit || parse_commit(commit)) { | 277 | if (!commit || parse_commit(commit)) { |
281 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); | 278 | cgit_print_error("Invalid commit reference: %s", rev); |
282 | return; | 279 | return; |
283 | } | 280 | } |
284 | 281 | ||