diff options
Diffstat (limited to 'cgit.c')
| -rw-r--r-- | cgit.c | 25 |
1 files changed, 22 insertions, 3 deletions
| @@ -60,6 +60,8 @@ static void process_cached_repolist(const char *path); | |||
| 60 | 60 | ||
| 61 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) | 61 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) |
| 62 | { | 62 | { |
| 63 | struct string_list_item *item; | ||
| 64 | |||
| 63 | if (!strcmp(name, "name")) | 65 | if (!strcmp(name, "name")) |
| 64 | repo->name = xstrdup(value); | 66 | repo->name = xstrdup(value); |
| 65 | else if (!strcmp(name, "clone-url")) | 67 | else if (!strcmp(name, "clone-url")) |
| @@ -86,7 +88,10 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) | |||
| 86 | repo->max_stats = cgit_find_stats_period(value, NULL); | 88 | repo->max_stats = cgit_find_stats_period(value, NULL); |
| 87 | else if (!strcmp(name, "module-link")) | 89 | else if (!strcmp(name, "module-link")) |
| 88 | repo->module_link= xstrdup(value); | 90 | repo->module_link= xstrdup(value); |
| 89 | else if (!strcmp(name, "section")) | 91 | else if (!prefixcmp(name, "module-link.")) { |
| 92 | item = string_list_append(&repo->submodules, name + 12); | ||
| 93 | item->util = xstrdup(value); | ||
| 94 | } else if (!strcmp(name, "section")) | ||
| 90 | repo->section = xstrdup(value); | 95 | repo->section = xstrdup(value); |
| 91 | else if (!strcmp(name, "readme") && value != NULL) | 96 | else if (!strcmp(name, "readme") && value != NULL) |
| 92 | repo->readme = xstrdup(value); | 97 | repo->readme = xstrdup(value); |
| @@ -300,6 +305,7 @@ static void querystring_cb(const char *name, const char *value) | |||
| 300 | ctx.qry.period = xstrdup(value); | 305 | ctx.qry.period = xstrdup(value); |
| 301 | } else if (!strcmp(name, "ss")) { | 306 | } else if (!strcmp(name, "ss")) { |
| 302 | ctx.qry.ssdiff = atoi(value); | 307 | ctx.qry.ssdiff = atoi(value); |
| 308 | ctx.qry.has_ssdiff = 1; | ||
| 303 | } else if (!strcmp(name, "all")) { | 309 | } else if (!strcmp(name, "all")) { |
| 304 | ctx.qry.show_all = atoi(value); | 310 | ctx.qry.show_all = atoi(value); |
| 305 | } else if (!strcmp(name, "context")) { | 311 | } else if (!strcmp(name, "context")) { |
| @@ -340,7 +346,6 @@ static void prepare_context(struct cgit_context *ctx) | |||
| 340 | ctx->cfg.max_repodesc_len = 80; | 346 | ctx->cfg.max_repodesc_len = 80; |
| 341 | ctx->cfg.max_blob_size = 0; | 347 | ctx->cfg.max_blob_size = 0; |
| 342 | ctx->cfg.max_stats = 0; | 348 | ctx->cfg.max_stats = 0; |
| 343 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | ||
| 344 | ctx->cfg.project_list = NULL; | 349 | ctx->cfg.project_list = NULL; |
| 345 | ctx->cfg.renamelimit = -1; | 350 | ctx->cfg.renamelimit = -1; |
| 346 | ctx->cfg.remove_suffix = 0; | 351 | ctx->cfg.remove_suffix = 0; |
| @@ -418,6 +423,17 @@ char *find_default_branch(struct cgit_repo *repo) | |||
| 418 | return ref; | 423 | return ref; |
| 419 | } | 424 | } |
| 420 | 425 | ||
| 426 | static char *guess_defbranch(const char *repo_path) | ||
| 427 | { | ||
| 428 | const char *ref; | ||
| 429 | unsigned char sha1[20]; | ||
| 430 | |||
| 431 | ref = resolve_ref("HEAD", sha1, 0, NULL); | ||
| 432 | if (!ref || prefixcmp(ref, "refs/heads/")) | ||
| 433 | return "master"; | ||
| 434 | return xstrdup(ref + 11); | ||
| 435 | } | ||
| 436 | |||
| 421 | static int prepare_repo_cmd(struct cgit_context *ctx) | 437 | static int prepare_repo_cmd(struct cgit_context *ctx) |
| 422 | { | 438 | { |
| 423 | char *tmp; | 439 | char *tmp; |
| @@ -444,10 +460,12 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
| 444 | } | 460 | } |
| 445 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 461 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
| 446 | 462 | ||
| 463 | if (!ctx->repo->defbranch) | ||
| 464 | ctx->repo->defbranch = guess_defbranch(ctx->repo->path); | ||
| 465 | |||
| 447 | if (!ctx->qry.head) { | 466 | if (!ctx->qry.head) { |
| 448 | ctx->qry.nohead = 1; | 467 | ctx->qry.nohead = 1; |
| 449 | ctx->qry.head = find_default_branch(ctx->repo); | 468 | ctx->qry.head = find_default_branch(ctx->repo); |
| 450 | ctx->repo->defbranch = ctx->qry.head; | ||
| 451 | } | 469 | } |
| 452 | 470 | ||
| 453 | if (!ctx->qry.head) { | 471 | if (!ctx->qry.head) { |
| @@ -471,6 +489,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
| 471 | cgit_print_docend(); | 489 | cgit_print_docend(); |
| 472 | return 1; | 490 | return 1; |
| 473 | } | 491 | } |
| 492 | sort_string_list(&ctx->repo->submodules); | ||
| 474 | cgit_prepare_repo_env(ctx->repo); | 493 | cgit_prepare_repo_env(ctx->repo); |
| 475 | return 0; | 494 | return 0; |
| 476 | } | 495 | } |
