From d6f6072560c963065b13c704fa1fa6f8950e4bac Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 31 Jul 2009 17:38:38 +0200 Subject: Add generic filter/plugin infrastructure The functions cgit_open_filter() and cgit_close_filter() can be used to execute filters on the output stream from cgit. Signed-off-by: Lars Hjemli --- cgit.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 2039ab1..779a464 100644 --- a/cgit.c +++ b/cgit.c @@ -17,6 +17,21 @@ const char *cgit_version = CGIT_VERSION; +struct cgit_filter *new_filter(const char *cmd, int extra_args) +{ + struct cgit_filter *f; + + if (!cmd) + return NULL; + + f = xmalloc(sizeof(struct cgit_filter)); + f->cmd = xstrdup(cmd); + f->argv = xmalloc((2 + extra_args) * sizeof(char *)); + f->argv[0] = f->cmd; + f->argv[1] = NULL; + return f; +} + void config_cb(const char *name, const char *value) { if (!strcmp(name, "root-title")) -- cgit v1.2.3 From 46b7abed99e957008c01c02cf612aa526ba92f04 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 31 Jul 2009 16:55:27 +0200 Subject: ui-tree: add support for source-filter option This new option is used to specify an external command which will be executed when displaying blob content in the tree view. Blob content will be written to STDIN of the filter and STDOUT from the filter will be included verbatim in the html output from cgit. The file name of the blob will be passed as the only argument to the filter command. Signed-off-by: Lars Hjemli --- cgit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 779a464..eb7b45d 100644 --- a/cgit.c +++ b/cgit.c @@ -100,6 +100,8 @@ void config_cb(const char *name, const char *value) ctx.cfg.max_repo_count = atoi(value); else if (!strcmp(name, "max-commit-count")) ctx.cfg.max_commit_count = atoi(value); + else if (!strcmp(name, "source-filter")) + ctx.cfg.source_filter = new_filter(value, 1); else if (!strcmp(name, "summary-log")) ctx.cfg.summary_log = atoi(value); else if (!strcmp(name, "summary-branches")) -- cgit v1.2.3 From f35db1cd2b75aac6952aa07713e44ca01fd89727 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 31 Jul 2009 17:42:57 +0200 Subject: ui-commit: add support for 'commit-filter' option This new option specifies a filter which is executed on the commit message, i.e. the commit message is written to the filters STDIN and the filters STDOUT is included verbatim as the commit message. This can be used to implement commit linking by creating a simple shell script in e.g. /usr/bin/cgit-commit-filter.sh like this: #/bin/sh sed -re 's|\b([0-9a-fA-F]{6,40})\b|\1|g' Signed-off-by: Lars Hjemli --- cgit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index eb7b45d..2cda554 100644 --- a/cgit.c +++ b/cgit.c @@ -90,6 +90,8 @@ void config_cb(const char *name, const char *value) ctx.cfg.cache_static_ttl = atoi(value); else if (!strcmp(name, "cache-dynamic-ttl")) ctx.cfg.cache_dynamic_ttl = atoi(value); + else if (!strcmp(name, "commit-filter")) + ctx.cfg.commit_filter = new_filter(value, 0); else if (!strcmp(name, "embedded")) ctx.cfg.embedded = atoi(value); else if (!strcmp(name, "max-message-length")) -- cgit v1.2.3 From e976df27952ca1e450c1c3d420532ac9f5e3036b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 9 Aug 2009 13:22:00 +0200 Subject: Add support for repo.commit-filter and repo.source-filter These options can be used to override the default commit- and source- filter settings per repository. Signed-off-by: Lars Hjemli --- cgit.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 2cda554..fd341b8 100644 --- a/cgit.c +++ b/cgit.c @@ -146,6 +146,10 @@ void config_cb(const char *name, const char *value) ctx.repo->max_stats = cgit_find_stats_period(value, NULL); else if (ctx.repo && !strcmp(name, "repo.module-link")) ctx.repo->module_link= xstrdup(value); + else if (ctx.repo && !strcmp(name, "repo.commit-filter")) + ctx.repo->commit_filter = new_filter(value, 0); + else if (ctx.repo && !strcmp(name, "repo.source-filter")) + ctx.repo->source_filter = new_filter(value, 1); else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { if (*value == '/') ctx.repo->readme = xstrdup(value); -- cgit v1.2.3 From 97b3d252629a8a3b9d356c2532dec7611438e4b9 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sun, 9 Aug 2009 13:39:44 +0200 Subject: cgit.c: allow repo.*-filter options to unset the current default If e.g. repo.commit-filter is specified as an empty string, this is now properly handled as disabling the global commit-filter setting for the current repository. Signed-off-by: Lars Hjemli --- cgit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index fd341b8..b3a98c1 100644 --- a/cgit.c +++ b/cgit.c @@ -21,7 +21,7 @@ struct cgit_filter *new_filter(const char *cmd, int extra_args) { struct cgit_filter *f; - if (!cmd) + if (!cmd || !cmd[0]) return NULL; f = xmalloc(sizeof(struct cgit_filter)); -- cgit v1.2.3