]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
filter: add support for email filter
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index 0be41b8b5b4cbb5457e12e22b26b70f2ab80c51a..f3fe56bb2748bb976061c819f24f4f7ddcd2caf8 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -89,6 +89,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
                        repo->commit_filter = cgit_new_filter(value, COMMIT);
                else if (!strcmp(name, "source-filter"))
                        repo->source_filter = cgit_new_filter(value, SOURCE);
                        repo->commit_filter = cgit_new_filter(value, COMMIT);
                else if (!strcmp(name, "source-filter"))
                        repo->source_filter = cgit_new_filter(value, SOURCE);
+               else if (!strcmp(name, "email-filter"))
+                       repo->email_filter = cgit_new_filter(value, EMAIL);
        }
 }
 
        }
 }
 
@@ -188,6 +190,8 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.about_filter = cgit_new_filter(value, ABOUT);
        else if (!strcmp(name, "commit-filter"))
                ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
                ctx.cfg.about_filter = cgit_new_filter(value, ABOUT);
        else if (!strcmp(name, "commit-filter"))
                ctx.cfg.commit_filter = cgit_new_filter(value, COMMIT);
+       else if (!strcmp(name, "email-filter"))
+               ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
        else if (!strcmp(name, "embedded"))
                ctx.cfg.embedded = atoi(value);
        else if (!strcmp(name, "max-atom-items"))
        else if (!strcmp(name, "embedded"))
                ctx.cfg.embedded = atoi(value);
        else if (!strcmp(name, "max-atom-items"))
@@ -706,11 +710,13 @@ 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.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)
        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)
        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->email_filter && repo->email_filter != ctx.cfg.email_filter)
+               cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
        if (repo->snapshots != ctx.cfg.snapshots) {
                char *tmp = build_snapshot_setting(repo->snapshots);
                fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
        if (repo->snapshots != ctx.cfg.snapshots) {
                char *tmp = build_snapshot_setting(repo->snapshots);
                fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
@@ -904,6 +910,8 @@ int main(int argc, const char **argv)
        const char *path;
        int err, ttl;
 
        const char *path;
        int err, ttl;
 
+       cgit_init_filters();
+
        prepare_context(&ctx);
        cgit_repolist.length = 0;
        cgit_repolist.count = 0;
        prepare_context(&ctx);
        cgit_repolist.length = 0;
        cgit_repolist.count = 0;
@@ -951,6 +959,7 @@ int main(int argc, const char **argv)
                ctx.cfg.cache_size = 0;
        err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
                            ctx.qry.raw, ttl, process_request, &ctx);
                ctx.cfg.cache_size = 0;
        err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
                            ctx.qry.raw, ttl, process_request, &ctx);
+       cgit_cleanup_filters();
        if (err)
                cgit_print_error("Error processing page: %s (%d)",
                                 strerror(err), err);
        if (err)
                cgit_print_error("Error processing page: %s (%d)",
                                 strerror(err), err);