aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cgit.c27
-rw-r--r--cgit.h4
2 files changed, 24 insertions, 7 deletions
diff --git a/cgit.c b/cgit.c
index f4dd6ef..5d6e488 100644
--- a/cgit.c
+++ b/cgit.c
@@ -26,13 +26,26 @@ void add_mimetype(const char *name, const char *value)
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, int extra_args) 29struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
30{ 30{
31 struct cgit_filter *f; 31 struct cgit_filter *f;
32 int extra_args;
32 33
33 if (!cmd || !cmd[0]) 34 if (!cmd || !cmd[0])
34 return NULL; 35 return NULL;
35 36
37 switch (filtertype) {
38 case SOURCE:
39 extra_args = 1;
40 break;
41
42 case ABOUT:
43 case COMMIT:
44 default:
45 extra_args = 0;
46 break;
47 }
48
36 f = xmalloc(sizeof(struct cgit_filter)); 49 f = xmalloc(sizeof(struct cgit_filter));
37 f->cmd = xstrdup(cmd); 50 f->cmd = xstrdup(cmd);
38 f->argv = xmalloc((2 + extra_args) * sizeof(char *)); 51 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
@@ -81,11 +94,11 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
81 repo->logo_link = xstrdup(value); 94 repo->logo_link = xstrdup(value);
82 else if (ctx.cfg.enable_filter_overrides) { 95 else if (ctx.cfg.enable_filter_overrides) {
83 if (!strcmp(name, "about-filter")) 96 if (!strcmp(name, "about-filter"))
84 repo->about_filter = new_filter(value, 0); 97 repo->about_filter = new_filter(value, ABOUT);
85 else if (!strcmp(name, "commit-filter")) 98 else if (!strcmp(name, "commit-filter"))
86 repo->commit_filter = new_filter(value, 0); 99 repo->commit_filter = new_filter(value, COMMIT);
87 else if (!strcmp(name, "source-filter")) 100 else if (!strcmp(name, "source-filter"))
88 repo->source_filter = new_filter(value, 1); 101 repo->source_filter = new_filter(value, SOURCE);
89 } 102 }
90} 103}
91 104
@@ -176,9 +189,9 @@ void config_cb(const char *name, const char *value)
176 else if (!strcmp(name, "cache-dynamic-ttl")) 189 else if (!strcmp(name, "cache-dynamic-ttl"))
177 ctx.cfg.cache_dynamic_ttl = atoi(value); 190 ctx.cfg.cache_dynamic_ttl = atoi(value);
178 else if (!strcmp(name, "about-filter")) 191 else if (!strcmp(name, "about-filter"))
179 ctx.cfg.about_filter = new_filter(value, 0); 192 ctx.cfg.about_filter = new_filter(value, ABOUT);
180 else if (!strcmp(name, "commit-filter")) 193 else if (!strcmp(name, "commit-filter"))
181 ctx.cfg.commit_filter = new_filter(value, 0); 194 ctx.cfg.commit_filter = new_filter(value, COMMIT);
182 else if (!strcmp(name, "embedded")) 195 else if (!strcmp(name, "embedded"))
183 ctx.cfg.embedded = atoi(value); 196 ctx.cfg.embedded = atoi(value);
184 else if (!strcmp(name, "max-atom-items")) 197 else if (!strcmp(name, "max-atom-items"))
@@ -208,7 +221,7 @@ void config_cb(const char *name, const char *value)
208 else if (!strcmp(name, "section-from-path")) 221 else if (!strcmp(name, "section-from-path"))
209 ctx.cfg.section_from_path = atoi(value); 222 ctx.cfg.section_from_path = atoi(value);
210 else if (!strcmp(name, "source-filter")) 223 else if (!strcmp(name, "source-filter"))
211 ctx.cfg.source_filter = new_filter(value, 1); 224 ctx.cfg.source_filter = new_filter(value, SOURCE);
212 else if (!strcmp(name, "summary-log")) 225 else if (!strcmp(name, "summary-log"))
213 ctx.cfg.summary_log = atoi(value); 226 ctx.cfg.summary_log = atoi(value);
214 else if (!strcmp(name, "summary-branches")) 227 else if (!strcmp(name, "summary-branches"))
diff --git a/cgit.h b/cgit.h
index b5f00fc..1f8b1be 100644
--- a/cgit.h
+++ b/cgit.h
@@ -51,6 +51,10 @@ typedef void (*configfn)(const char *name, const char *value);
51typedef void (*filepair_fn)(struct diff_filepair *pair); 51typedef void (*filepair_fn)(struct diff_filepair *pair);
52typedef void (*linediff_fn)(char *line, int len); 52typedef void (*linediff_fn)(char *line, int len);
53 53
54typedef enum {
55 ABOUT, COMMIT, SOURCE
56} filter_type;
57
54struct cgit_filter { 58struct cgit_filter {
55 char *cmd; 59 char *cmd;
56 char **argv; 60 char **argv;