]> granicus.if.org Git - cgit/commitdiff
filter: add fprintf_filter function
authorJohn Keeping <john@keeping.me.uk>
Sun, 12 Jan 2014 17:13:51 +0000 (17:13 +0000)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 14 Jan 2014 01:00:07 +0000 (02:00 +0100)
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>
cgit.c
cgit.h
filter.c

diff --git a/cgit.c b/cgit.c
index 0be41b8b5b4cbb5457e12e22b26b70f2ab80c51a..29b658e7d2c1960b5caab306b1af066feab36092 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -706,11 +706,11 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
        fprintf(f, "repo.enable-log-linecount=%d\n",
                repo->enable_log_linecount);
        if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter)
-               fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd);
+               cgit_fprintf_filter(repo->about_filter, f, "repo.about-filter=");
        if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter)
-               fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd);
+               cgit_fprintf_filter(repo->commit_filter, f, "repo.commit-filter=");
        if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
-               fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd);
+               cgit_fprintf_filter(repo->source_filter, f, "repo.source-filter=");
        if (repo->snapshots != ctx.cfg.snapshots) {
                char *tmp = build_snapshot_setting(repo->snapshots);
                fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
diff --git a/cgit.h b/cgit.h
index e6e7715bbaa8c146676005428250a6dc4a8687a4..9b4be26bc342e551b12699e82d488d2b9d18ca32 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -345,6 +345,7 @@ extern int cgit_parse_snapshots_mask(const char *str);
 
 extern int cgit_open_filter(struct cgit_filter *filter, ...);
 extern int cgit_close_filter(struct cgit_filter *filter);
+extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
 extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
 
 extern void cgit_prepare_repo_env(struct cgit_repo * repo);
index d8c0116df39bd20a96f183b4e992b969afdb7623..80cf68956bc5291a74cbe029ebf449af625bedb0 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -63,6 +63,11 @@ done:
 
 }
 
+void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix)
+{
+       fprintf(f, "%s%s\n", prefix, filter->cmd);
+}
+
 struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 {
        struct cgit_filter *f;