diff options
| author | 2012-03-19 06:00:18 (JST) | |
|---|---|---|
| committer | 2012-03-19 06:00:18 (JST) | |
| commit | 181b6e789b79fc385e5ec75b2b83f01192d54051 (patch) | |
| tree | 8888b5eb9c6674b69bcb8f508f9d6f548fc1fed3 | |
| parent | 2b9fab8d30420d935745c4d84ea22412ab2485e5 (diff) | |
| parent | 5293c8b7992bf3211b6bde7acbbd4e74ffd926d4 (diff) | |
| download | cgit-181b6e789b79fc385e5ec75b2b83f01192d54051.zip cgit-181b6e789b79fc385e5ec75b2b83f01192d54051.tar.gz | |
Merge branch 'jp/defbranch'
| -rw-r--r-- | cgit.c | 15 | ||||
| -rw-r--r-- | cgitrc.5.txt | 3 | ||||
| -rw-r--r-- | shared.c | 1 | ||||
| -rw-r--r-- | ui-repolist.c | 3 |
4 files changed, 18 insertions, 4 deletions
| @@ -421,6 +421,17 @@ char *find_default_branch(struct cgit_repo *repo) | |||
| 421 | return ref; | 421 | return ref; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | static char *guess_defbranch(const char *repo_path) | ||
| 425 | { | ||
| 426 | const char *ref; | ||
| 427 | unsigned char sha1[20]; | ||
| 428 | |||
| 429 | ref = resolve_ref("HEAD", sha1, 0, NULL); | ||
| 430 | if (!ref || prefixcmp(ref, "refs/heads/")) | ||
| 431 | return "master"; | ||
| 432 | return xstrdup(ref + 11); | ||
| 433 | } | ||
| 434 | |||
| 424 | static int prepare_repo_cmd(struct cgit_context *ctx) | 435 | static int prepare_repo_cmd(struct cgit_context *ctx) |
| 425 | { | 436 | { |
| 426 | char *tmp; | 437 | char *tmp; |
| @@ -447,10 +458,12 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
| 447 | } | 458 | } |
| 448 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 459 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
| 449 | 460 | ||
| 461 | if (!ctx->repo->defbranch) | ||
| 462 | ctx->repo->defbranch = guess_defbranch(ctx->repo->path); | ||
| 463 | |||
| 450 | if (!ctx->qry.head) { | 464 | if (!ctx->qry.head) { |
| 451 | ctx->qry.nohead = 1; | 465 | ctx->qry.nohead = 1; |
| 452 | ctx->qry.head = find_default_branch(ctx->repo); | 466 | ctx->qry.head = find_default_branch(ctx->repo); |
| 453 | ctx->repo->defbranch = ctx->qry.head; | ||
| 454 | } | 467 | } |
| 455 | 468 | ||
| 456 | if (!ctx->qry.head) { | 469 | if (!ctx->qry.head) { |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index b4ad2ac..fab0e0a 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
| @@ -377,7 +377,8 @@ repo.commit-filter:: | |||
| 377 | repo.defbranch:: | 377 | repo.defbranch:: |
| 378 | The name of the default branch for this repository. If no such branch | 378 | The name of the default branch for this repository. If no such branch |
| 379 | exists in the repository, the first branch name (when sorted) is used | 379 | exists in the repository, the first branch name (when sorted) is used |
| 380 | as default instead. Default value: "master". | 380 | as default instead. Default value: branch pointed to by HEAD, or |
| 381 | "master" if there is no suitable HEAD. | ||
| 381 | 382 | ||
| 382 | repo.desc:: | 383 | repo.desc:: |
| 383 | The value to show as repository description. Default value: none. | 384 | The value to show as repository description. Default value: none. |
| @@ -55,7 +55,6 @@ struct cgit_repo *cgit_add_repo(const char *url) | |||
| 55 | ret->desc = "[no description]"; | 55 | ret->desc = "[no description]"; |
| 56 | ret->owner = NULL; | 56 | ret->owner = NULL; |
| 57 | ret->section = ctx.cfg.section; | 57 | ret->section = ctx.cfg.section; |
| 58 | ret->defbranch = "master"; | ||
| 59 | ret->snapshots = ctx.cfg.snapshots; | 58 | ret->snapshots = ctx.cfg.snapshots; |
| 60 | ret->enable_commit_graph = ctx.cfg.enable_commit_graph; | 59 | ret->enable_commit_graph = ctx.cfg.enable_commit_graph; |
| 61 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 60 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
diff --git a/ui-repolist.c b/ui-repolist.c index a09a689..d946f32 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
| @@ -45,7 +45,8 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) | |||
| 45 | return 1; | 45 | return 1; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 48 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch ? |
| 49 | repo->defbranch : "master"); | ||
| 49 | if (stat(path, &s) == 0) { | 50 | if (stat(path, &s) == 0) { |
| 50 | *mtime = s.st_mtime; | 51 | *mtime = s.st_mtime; |
| 51 | r->mtime = *mtime; | 52 | r->mtime = *mtime; |
