aboutsummaryrefslogtreecommitdiffstats
path: root/cgit.c
diff options
context:
space:
mode:
authorGravatar Ferry Huberts <ferry.huberts@pelagic.nl>2011-03-23 19:57:41 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2011-03-26 19:03:41 (JST)
commit9240a828d13fa8f6a9e379b94b2061ca83e6199c (patch)
treea9670bca61be8d3e0349b690a4a83b2128a583d2 /cgit.c
parentcc59ee502646dc4e3d0f8bbe29b24c7fa3f0d2dd (diff)
downloadcgit-9240a828d13fa8f6a9e379b94b2061ca83e6199c.zip
cgit-9240a828d13fa8f6a9e379b94b2061ca83e6199c.tar.gz
new_filter: determine extra_args from filter type
Currently the number of extra arguments is linked hard to the type of the filter. This is also logical since it would be confusing to have a different number of arguments for the same type of filter depending on the context under which the filter is run (unless ofcourse one the parameters would make the context clear, which is currently not the case). Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c27
1 files changed, 20 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"))