about summary refs log tree commit diff stats
path: root/cgit.c
diff options
context:
space:
mode:
authorJason A. Donenfeld2013-05-25 16:32:37 +0200
committerJason A. Donenfeld2013-05-25 20:33:28 +0200
commitcd4c77d989983778432363061e99219f034c3717 (patch)
treea394b7960e7105c7dbcb130721298a49d49b8a75 /cgit.c
parentui-summary: Pass filename to about-filter (diff)
downloadcgit-cd4c77d989983778432363061e99219f034c3717.tar.gz
cgit-cd4c77d989983778432363061e99219f034c3717.zip
readme: Accept multiple candidates and test them.
The readme variable may now contain multiple space deliminated entries,
which per usual are either a filepath or a git ref filepath. If multiple
are specified, cgit will now select the first one in the list that
exists. This is to make it easier to specify multiple default readme
types in the main cgitrc file and have them automatically get applied to
each repo based on what exists.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
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