about summary refs log tree commit diff stats
path: root/cgit.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/cgit.c b/cgit.c index 04682be..f738b83 100644 --- a/cgit.c +++ b/cgit.c
@@ -14,6 +14,8 @@
14#include "html.h" 14#include "html.h"
15#include "ui-shared.h" 15#include "ui-shared.h"
16#include "ui-stats.h" 16#include "ui-stats.h"
17#include "ui-blob.h"
18#include "ui-summary.h"
17#include "scan-tree.h" 19#include "scan-tree.h"
18 20
19const char *cgit_version = CGIT_VERSION; 21const char *cgit_version = CGIT_VERSION;
@@ -469,6 +471,38 @@ static char *guess_defbranch(void)
469 return xstrdup(ref + 11); 471 return xstrdup(ref + 11);
470} 472}
471 473
474static void choose_readme(struct cgit_repo *repo)
475{
476 char *entry, *filename, *ref;
477
478 /* If there's no space, we skip the possibly expensive
479 * selection process. */
480 if (!repo->readme || !strchr(repo->readme, ' '))
481 return;
482
483 for (entry = strtok(repo->readme, " "); entry; entry = strtok(NULL, " ")) {
484 cgit_parse_readme(entry, NULL, &filename, &ref, repo);
485 if (!(*filename)) {
486 free(filename);
487 free(ref);
488 continue;
489 }
490 if (*ref && cgit_ref_path_exists(filename, ref)) {
491 free(filename);
492 free(ref);
493 break;
494 }
495 if (!access(filename, R_OK)) {
496 free(filename);
497 free(ref);
498 break;
499 }
500 free(filename);
501 free(ref);
502 }
503 repo->readme = entry;
504}
505
472static int prepare_repo_cmd(struct cgit_context *ctx) 506static int prepare_repo_cmd(struct cgit_context *ctx)
473{ 507{
474 unsigned char sha1[20]; 508 unsigned char sha1[20];
@@ -537,6 +571,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
537 } 571 }
538 sort_string_list(&ctx->repo->submodules); 572 sort_string_list(&ctx->repo->submodules);
539 cgit_prepare_repo_env(ctx->repo); 573 cgit_prepare_repo_env(ctx->repo);
574 choose_readme(ctx->repo);
540 return 0; 575 return 0;
541} 576}
542 577