diff options
Diffstat (limited to 'cgit.c')
-rw-r--r-- | cgit.c | 59 |
1 files changed, 39 insertions, 20 deletions
@@ -99,6 +99,10 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va if (repo->readme.items == ctx.cfg.readme.items) memset(&repo->readme, 0, sizeof(repo->readme)); string_list_append(&repo->readme, xstrdup(value)); + } else if (!strcmp(name, "license") && value != NULL) { + if (repo->license.items == ctx.cfg.license.items) + memset(&repo->license, 0, sizeof(repo->license)); + string_list_append(&repo->license, xstrdup(value)); } else if (!strcmp(name, "logo") && value != NULL) repo->logo = xstrdup(value); else if (!strcmp(name, "logo-link") && value != NULL) @@ -135,6 +139,8 @@ static void config_cb(const char *name, const char *value) repo_config(ctx.repo, arg, value); else if (!strcmp(name, "readme")) string_list_append(&ctx.cfg.readme, xstrdup(value)); + else if (!strcmp(name, "license")) + string_list_append(&ctx.cfg.license, xstrdup(value)); else if (!strcmp(name, "root-title")) ctx.cfg.root_title = xstrdup(value); else if (!strcmp(name, "root-desc")) @@ -213,6 +219,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.cache_dynamic_ttl = atoi(value); else if (!strcmp(name, "cache-about-ttl")) ctx.cfg.cache_about_ttl = atoi(value); + else if (!strcmp(name, "cache-license-ttl")) + ctx.cfg.cache_license_ttl = atoi(value); else if (!strcmp(name, "cache-snapshot-ttl")) ctx.cfg.cache_snapshot_ttl = atoi(value); else if (!strcmp(name, "case-sensitive-sort")) @@ -367,6 +375,7 @@ static void prepare_context(void) ctx.cfg.cache_max_create_time = 5; ctx.cfg.cache_root = CGIT_CACHE_ROOT; ctx.cfg.cache_about_ttl = 15; + ctx.cfg.cache_license_ttl = 15; ctx.cfg.cache_snapshot_ttl = 5; ctx.cfg.cache_repo_ttl = 5; ctx.cfg.cache_root_ttl = 5; @@ -494,46 +503,46 @@ static char *guess_defbranch(void) } /* The caller must free filename and ref after calling this. */ -static inline void parse_readme(const char *readme, char **filename, char **ref, struct cgit_repo *repo) +static inline void parse_info_file(const char *file, char **filename, char **ref, struct cgit_repo *repo) { const char *colon; *filename = NULL; *ref = NULL; - if (!readme || !readme[0]) + if (!file || !file[0]) return; - /* Check if the readme is tracked in the git repo. */ - colon = strchr(readme, ':'); + /* Check if the file is tracked in the git repo. */ + colon = strchr(file, ':'); if (colon && strlen(colon) > 1) { /* If it starts with a colon, we want to use * the default branch */ - if (colon == readme && repo->defbranch) + if (colon == file && repo->defbranch) *ref = xstrdup(repo->defbranch); else - *ref = xstrndup(readme, colon - readme); - readme = colon + 1; + *ref = xstrndup(file, colon - file); + file = colon + 1; } - /* Prepend repo path to relative readme path unless tracked. */ - if (!(*ref) && readme[0] != '/') - *filename = fmtalloc("%s/%s", repo->path, readme); + /* Prepend repo path to relative file path unless tracked. */ + if (!(*ref) && file[0] != '/') + *filename = fmtalloc("%s/%s", repo->path, file); else - *filename = xstrdup(readme); + *filename = xstrdup(file); } -static void choose_readme(struct cgit_repo *repo) +static void choose_string_list_item(struct cgit_repo *repo, struct string_list *file) { int found; char *filename, *ref; struct string_list_item *entry; - if (!repo->readme.nr) + if (!file->nr) return; found = 0; - for_each_string_list_item(entry, &repo->readme) { - parse_readme(entry->string, &filename, &ref, repo); + for_each_string_list_item(entry, file) { + parse_info_file(entry->string, &filename, &ref, repo); if (!filename) { free(filename); free(ref); @@ -552,11 +561,11 @@ static void choose_readme(struct cgit_repo *repo) free(filename); free(ref); } - repo->readme.strdup_strings = 1; - string_list_clear(&repo->readme, 0); - repo->readme.strdup_strings = 0; + file->strdup_strings = 1; + string_list_clear(file, 0); + file->strdup_strings = 0; if (found) - string_list_append(&repo->readme, filename)->util = ref; + string_list_append(file, filename)->util = ref; } static void print_no_repo_clone_urls(const char *url) @@ -636,7 +645,8 @@ static int prepare_repo_cmd(int nongit) } string_list_sort(&ctx.repo->submodules); cgit_prepare_repo_env(ctx.repo); - choose_readme(ctx.repo); + choose_string_list_item(ctx.repo, &ctx.repo->readme); + choose_string_list_item(ctx.repo, &ctx.repo->license); return 0; } @@ -804,6 +814,12 @@ static void print_repo(FILE *f, struct cgit_repo *repo) else fprintf(f, "repo.readme=%s\n", item->string); } + for_each_string_list_item(item, &repo->license) { + if (item->util) + fprintf(f, "repo.license=%s:%s\n", (char *)item->util, item->string); + else + fprintf(f, "repo.license=%s\n", item->string); + } if (repo->defbranch) fprintf(f, "repo.defbranch=%s\n", repo->defbranch); if (repo->extra_head_content) @@ -1034,6 +1050,9 @@ static int calc_ttl(void) if (!strcmp(ctx.qry.page, "about")) return ctx.cfg.cache_about_ttl; + if (!strcmp(ctx.qry.page, "license")) + return ctx.cfg.cache_license_ttl; + if (!strcmp(ctx.qry.page, "snapshot")) return ctx.cfg.cache_snapshot_ttl; |