|
diff --git a/cgit.c b/cgit.c index 38bc136..d4fcfa7 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -388,96 +388,102 @@ static int prepare_repo_cmd(struct cgit_context *ctx) |
388 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
388 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
389 | |
389 | |
390 | if (!ctx->qry.head) { |
390 | if (!ctx->qry.head) { |
391 | ctx->qry.nohead = 1; |
391 | ctx->qry.nohead = 1; |
392 | ctx->qry.head = find_default_branch(ctx->repo); |
392 | ctx->qry.head = find_default_branch(ctx->repo); |
393 | ctx->repo->defbranch = ctx->qry.head; |
393 | ctx->repo->defbranch = ctx->qry.head; |
394 | } |
394 | } |
395 | |
395 | |
396 | if (!ctx->qry.head) { |
396 | if (!ctx->qry.head) { |
397 | cgit_print_http_headers(ctx); |
397 | cgit_print_http_headers(ctx); |
398 | cgit_print_docstart(ctx); |
398 | cgit_print_docstart(ctx); |
399 | cgit_print_pageheader(ctx); |
399 | cgit_print_pageheader(ctx); |
400 | cgit_print_error("Repository seems to be empty"); |
400 | cgit_print_error("Repository seems to be empty"); |
401 | cgit_print_docend(); |
401 | cgit_print_docend(); |
402 | return 1; |
402 | return 1; |
403 | } |
403 | } |
404 | |
404 | |
405 | if (get_sha1(ctx->qry.head, sha1)) { |
405 | if (get_sha1(ctx->qry.head, sha1)) { |
406 | tmp = xstrdup(ctx->qry.head); |
406 | tmp = xstrdup(ctx->qry.head); |
407 | ctx->qry.head = ctx->repo->defbranch; |
407 | ctx->qry.head = ctx->repo->defbranch; |
408 | ctx->page.status = 404; |
408 | ctx->page.status = 404; |
409 | ctx->page.statusmsg = "not found"; |
409 | ctx->page.statusmsg = "not found"; |
410 | cgit_print_http_headers(ctx); |
410 | cgit_print_http_headers(ctx); |
411 | cgit_print_docstart(ctx); |
411 | cgit_print_docstart(ctx); |
412 | cgit_print_pageheader(ctx); |
412 | cgit_print_pageheader(ctx); |
413 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
413 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
414 | cgit_print_docend(); |
414 | cgit_print_docend(); |
415 | return 1; |
415 | return 1; |
416 | } |
416 | } |
417 | return 0; |
417 | return 0; |
418 | } |
418 | } |
419 | |
419 | |
420 | static void process_request(void *cbdata) |
420 | static void process_request(void *cbdata) |
421 | { |
421 | { |
422 | struct cgit_context *ctx = cbdata; |
422 | struct cgit_context *ctx = cbdata; |
423 | struct cgit_cmd *cmd; |
423 | struct cgit_cmd *cmd; |
424 | |
424 | |
425 | cmd = cgit_get_cmd(ctx); |
425 | cmd = cgit_get_cmd(ctx); |
426 | if (!cmd) { |
426 | if (!cmd) { |
427 | ctx->page.title = "cgit error"; |
427 | ctx->page.title = "cgit error"; |
428 | cgit_print_http_headers(ctx); |
428 | cgit_print_http_headers(ctx); |
429 | cgit_print_docstart(ctx); |
429 | cgit_print_docstart(ctx); |
430 | cgit_print_pageheader(ctx); |
430 | cgit_print_pageheader(ctx); |
431 | cgit_print_error("Invalid request"); |
431 | cgit_print_error("Invalid request"); |
432 | cgit_print_docend(); |
432 | cgit_print_docend(); |
433 | return; |
433 | return; |
434 | } |
434 | } |
435 | |
435 | |
| |
436 | /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" |
| |
437 | * in-project path limit to be made available at ctx->qry.vpath. |
| |
438 | * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). |
| |
439 | */ |
| |
440 | ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL; |
| |
441 | |
436 | if (cmd->want_repo && !ctx->repo) { |
442 | if (cmd->want_repo && !ctx->repo) { |
437 | cgit_print_http_headers(ctx); |
443 | cgit_print_http_headers(ctx); |
438 | cgit_print_docstart(ctx); |
444 | cgit_print_docstart(ctx); |
439 | cgit_print_pageheader(ctx); |
445 | cgit_print_pageheader(ctx); |
440 | cgit_print_error(fmt("No repository selected")); |
446 | cgit_print_error(fmt("No repository selected")); |
441 | cgit_print_docend(); |
447 | cgit_print_docend(); |
442 | return; |
448 | return; |
443 | } |
449 | } |
444 | |
450 | |
445 | if (ctx->repo && prepare_repo_cmd(ctx)) |
451 | if (ctx->repo && prepare_repo_cmd(ctx)) |
446 | return; |
452 | return; |
447 | |
453 | |
448 | if (cmd->want_layout) { |
454 | if (cmd->want_layout) { |
449 | cgit_print_http_headers(ctx); |
455 | cgit_print_http_headers(ctx); |
450 | cgit_print_docstart(ctx); |
456 | cgit_print_docstart(ctx); |
451 | cgit_print_pageheader(ctx); |
457 | cgit_print_pageheader(ctx); |
452 | } |
458 | } |
453 | |
459 | |
454 | cmd->fn(ctx); |
460 | cmd->fn(ctx); |
455 | |
461 | |
456 | if (cmd->want_layout) |
462 | if (cmd->want_layout) |
457 | cgit_print_docend(); |
463 | cgit_print_docend(); |
458 | } |
464 | } |
459 | |
465 | |
460 | int cmp_repos(const void *a, const void *b) |
466 | int cmp_repos(const void *a, const void *b) |
461 | { |
467 | { |
462 | const struct cgit_repo *ra = a, *rb = b; |
468 | const struct cgit_repo *ra = a, *rb = b; |
463 | return strcmp(ra->url, rb->url); |
469 | return strcmp(ra->url, rb->url); |
464 | } |
470 | } |
465 | |
471 | |
466 | char *build_snapshot_setting(int bitmap) |
472 | char *build_snapshot_setting(int bitmap) |
467 | { |
473 | { |
468 | const struct cgit_snapshot_format *f; |
474 | const struct cgit_snapshot_format *f; |
469 | char *result = xstrdup(""); |
475 | char *result = xstrdup(""); |
470 | char *tmp; |
476 | char *tmp; |
471 | int len; |
477 | int len; |
472 | |
478 | |
473 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
479 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
474 | if (f->bit & bitmap) { |
480 | if (f->bit & bitmap) { |
475 | tmp = result; |
481 | tmp = result; |
476 | result = xstrdup(fmt("%s%s ", tmp, f->suffix)); |
482 | result = xstrdup(fmt("%s%s ", tmp, f->suffix)); |
477 | free(tmp); |
483 | free(tmp); |
478 | } |
484 | } |
479 | } |
485 | } |
480 | len = strlen(result); |
486 | len = strlen(result); |
481 | if (len) |
487 | if (len) |
482 | result[len - 1] = '\0'; |
488 | result[len - 1] = '\0'; |
483 | return result; |
489 | return result; |
|