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.
| -rw-r--r-- | source/cgit.c | 45 | |
| -rwxr-xr-x | tests/t0003-cache.sh | 47 |
2 files changed, 80 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; diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 53a6d5b..02622b5 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -467,6 +467,53 @@ test_expect_success 'a cached scan leaves the description placeholder out' ' ! grep "<meta name=.description." tmp ' +# The list is read back under the global settings, so what a repository set +# against them has to come back with it. This one sorts its branches by name +# where the site sorts by age, turns the site's about filter off and links a +# submodule of its own. A list scanned without the global filter is no good +# to a config that sets one, as it says nothing of the filter turned off. +test_expect_success 'a cached scan keeps what a repository sets' ' + mkrepo kept/one 1 && + sub=$(git -C kept/one rev-parse HEAD) && + ( + cd kept/one && + git update-index --add --cacheinfo 160000,$sub,submod && + git commit -m gitlink && + git branch aaa && + newest=$(echo newest | GIT_COMMITTER_DATE="@2000000000 +0000" git commit-tree HEAD^{tree} -p HEAD) && + git update-ref refs/heads/zzz $newest + ) && + { + echo "branch-sort=name" && + echo "about-filter=" && + echo "readme=:file-1" && + echo "module-link.submod=https://example.org/s/?id=%s" + } >kept/one/.git/cgitrc && + { + echo "virtual-root=/" && + echo "cache-root=$PWD/cache6" && + echo "cache-size=64" && + echo "trust-scan-config=1" && + echo "branch-sort=age" && + echo "scan-path=$PWD/kept" + } >unfilteredrc && + { + echo "about-filter=exec:$FILTER_DIRECTORY/dump.sh" && + cat unfilteredrc + } >keptrc && + rm -rf cache6 && mkdir cache6 && + cgit_rc unfilteredrc "url=" >/dev/null && + cgit_rc keptrc "url=" >/dev/null && + cgit_rc keptrc "url=one/refs/" >tmp && + sed -n "s/^<tr class=.branch.><td><a [^>]*>\([a-z]*\)<.*/\1/p" tmp >branches && + test_write_lines aaa master zzz >expect && + test_cmp expect branches && + cgit_rc keptrc "url=one/about/" >tmp && + grep "<pre class=.plaintext.>1$" tmp && + cgit_rc keptrc "url=one/tree/" >tmp && + grep "href=.https://example.org/s/?id=$sub." tmp +' + # A cache-size below zero turns the page cache off, and the scan with it, so # the cache directory stays empty. test_expect_success 'a negative cache-size leaves the scan uncached' ' |
