diff options
author | John Keeping <john@keeping.me.uk> | 2014-01-13 02:13:51 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-01-14 10:00:07 (JST) |
commit | 632efb25c07c1b014a4e8cfbbea759f517c2aaf6 (patch) | |
tree | d749ef94576b829a4b8fc5ef330beb27de452bf1 | |
parent | ed3497b0de6634350cd17b320538fba918d4084c (diff) | |
download | cgit-632efb25c07c1b014a4e8cfbbea759f517c2aaf6.zip cgit-632efb25c07c1b014a4e8cfbbea759f517c2aaf6.tar.gz |
filter: add fprintf_filter function
This stops the code in cgit.c::print_repo needing to inspect the
cgit_filter structure, meaning that we can abstract out different filter
types that will have different fields that need to be printed.
Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r-- | cgit.c | 6 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | filter.c | 5 |
3 files changed, 9 insertions, 3 deletions
@@ -706,11 +706,11 @@ static void print_repo(FILE *f, struct cgit_repo *repo) | |||
706 | fprintf(f, "repo.enable-log-linecount=%d\n", | 706 | fprintf(f, "repo.enable-log-linecount=%d\n", |
707 | repo->enable_log_linecount); | 707 | repo->enable_log_linecount); |
708 | if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) | 708 | if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter) |
709 | fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd); | 709 | cgit_fprintf_filter(repo->about_filter, f, "repo.about-filter="); |
710 | if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) | 710 | if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter) |
711 | fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd); | 711 | cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter="); |
712 | if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) | 712 | if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter) |
713 | fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd); | 713 | cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter="); |
714 | if (repo->snapshots != ctx.cfg.snapshots) { | 714 | if (repo->snapshots != ctx.cfg.snapshots) { |
715 | char *tmp = build_snapshot_setting(repo->snapshots); | 715 | char *tmp = build_snapshot_setting(repo->snapshots); |
716 | fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); | 716 | fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); |
@@ -345,6 +345,7 @@ extern int cgit_parse_snapshots_mask(const char *str); | |||
345 | 345 | ||
346 | extern int cgit_open_filter(struct cgit_filter *filter, ...); | 346 | extern int cgit_open_filter(struct cgit_filter *filter, ...); |
347 | extern int cgit_close_filter(struct cgit_filter *filter); | 347 | extern int cgit_close_filter(struct cgit_filter *filter); |
348 | extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix); | ||
348 | extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype); | 349 | extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype); |
349 | 350 | ||
350 | extern void cgit_prepare_repo_env(struct cgit_repo * repo); | 351 | extern void cgit_prepare_repo_env(struct cgit_repo * repo); |
@@ -63,6 +63,11 @@ done: | |||
63 | 63 | ||
64 | } | 64 | } |
65 | 65 | ||
66 | void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix) | ||
67 | { | ||
68 | fprintf(f, "%s%s\n", prefix, filter->cmd); | ||
69 | } | ||
70 | |||
66 | struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) | 71 | struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) |
67 | { | 72 | { |
68 | struct cgit_filter *f; | 73 | struct cgit_filter *f; |