Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep a repository's own settings in a cached scan
A scanned repository is read back from the cached list under the global
settings, so a setting that only differed from them by being off, or by
naming the default value, came back as the global one. branch-sort was
written only for age, per-path module links not at all, and a filter a
repository turned off left no line behind.
Writing an empty value for a filter turned off makes the list depend on
whether each global filter is set, so the scan key names that too.
Diffstat (limited to 'source/cgit.c')
| -rw-r--r-- | source/cgit.c | 45 |
1 file changed, 33 insertions, 12 deletions
diff --git a/source/cgit.c b/source/cgit.c index 9ec7df1..d982fdb 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -203,6 +203,22 @@ static char *build_snapshot_setting(int mask) return strbuf_detach(&result, NULL); } +/* + * Only a filter the repository set itself is written, since one it kept from + * the global settings is copied in again when the list is read back. An empty + * value stands for a repository that turned the global filter off. + */ +static void print_filter(FILE *f, const char *key, struct cgit_filter *filter, + struct cgit_filter *global) +{ + if (filter == global) + return; + if (filter) + cgit_fprintf_filter(filter, f, key); + else + fprintf(f, "%s\n", key); +} + static void print_repo(FILE *f, struct cgit_repo *repo) { struct string_list_item *item; @@ -229,6 +245,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.head-content=%s\n", repo->head_content); if (repo->module_link) fprintf(f, "repo.module-link=%s\n", repo->module_link); + for_each_string_list_item(item, &repo->submodules) + fprintf(f, "repo.module-link.%s=%s\n", item->string, (char *)item->util); if (repo->section) fprintf(f, "repo.section=%s\n", repo->section); if (repo->clone_url) @@ -240,16 +258,11 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.enable-log-filecount=%d\n", repo->enable_log_filecount); fprintf(f, "repo.enable-log-linecount=%d\n", repo->enable_log_linecount); fprintf(f, "repo.enable-mailmap=%d\n", repo->enable_mailmap); - if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) - cgit_fprintf_filter(repo->about_filter, f, "repo.about-filter="); - if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) - cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter="); - if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) - cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter="); - if (repo->email_filter && repo->email_filter != ctx.cfg.email_filter) - cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter="); - if (repo->trailer_filter && repo->trailer_filter != ctx.cfg.trailer_filter) - cgit_fprintf_filter(repo->trailer_filter, f, "repo.trailer-filter="); + print_filter(f, "repo.about-filter=", repo->about_filter, ctx.cfg.about_filter); + print_filter(f, "repo.commit-filter=", repo->commit_filter, ctx.cfg.commit_filter); + print_filter(f, "repo.source-filter=", repo->source_filter, ctx.cfg.source_filter); + print_filter(f, "repo.email-filter=", repo->email_filter, ctx.cfg.email_filter); + print_filter(f, "repo.trailer-filter=", repo->trailer_filter, ctx.cfg.trailer_filter); if (repo->snapshots != ctx.cfg.snapshots) { char *formats = build_snapshot_setting(repo->snapshots); fprintf(f, "repo.snapshots=%s\n", formats); @@ -267,8 +280,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links); fprintf(f, "repo.enable-commit-trailers=%d\n", repo->enable_commit_trailers); fprintf(f, "repo.enable-html-serving=%d\n", repo->enable_html_serving); - if (repo->branch_sort == 1) - fprintf(f, "repo.branch-sort=age\n"); + if (repo->branch_sort != ctx.cfg.branch_sort) + fprintf(f, "repo.branch-sort=%s\n", repo->branch_sort ? "age" : "name"); if (repo->commit_sort == 1) fprintf(f, "repo.commit-sort=date\n"); else if (repo->commit_sort == 2) @@ -417,6 +430,14 @@ static void build_scan_key(struct strbuf *key, const char *path) ctx.cfg.enable_mailmap, ctx.cfg.enable_remote_branches, ctx.cfg.enable_subject_links, + // A filter kept from the global settings follows cgitrc when + // the list is read, but whether one is set decides what is + // written for a repository that turned it off. + ctx.cfg.about_filter != NULL, + ctx.cfg.commit_filter != NULL, + ctx.cfg.email_filter != NULL, + ctx.cfg.source_filter != NULL, + ctx.cfg.trailer_filter != NULL, }; size_t i; |
