[PATCH] ui-tree.c: check source filter if set globally

Jamie Couture jamie.couture at gmail.com
Wed Jul 30 20:53:21 CEST 2014


When parsing cgitrc users that place 'source-filter' setting after
'scan-path' find their source filter is never run.

  scan-path=/home/git/repositories
  source-filter=/usr/local/lib/cgit/filters/syntax-highlighting.sh

ui-tree.c will print out our repository objects, but will only consider
ctx.repo->source_filter struct and not checking ctx.cfg.source_filter

The value would have been set in shared.c, via cgit_add_repo() but this
isn't the case when using scan-path, because we have not yet processed
the source-filter line in our cgitrc, and thus the source_filter struct
will not be initialized.

Checking the global configuration in ui-tree.c is necessary to avoid an
issue where users declare the source filter after scan-path.

Signed-off-by: Jamie Couture <jamie.couture at gmail.com>
---
 ui-tree.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/ui-tree.c b/ui-tree.c
index e4c3d22..f52f15c 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -22,6 +22,7 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
 {
 	unsigned long lineno, idx;
 	const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
+	struct cgit_filter *source_filter = NULL;
 
 	html("<table summary='blob content' class='blob'>\n");
 
@@ -45,11 +46,17 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
 	}
 
 	if (ctx.repo->source_filter) {
+		source_filter = ctx.repo->source_filter;
+	} else if (ctx.cfg.source_filter) {
+		source_filter = ctx.cfg.source_filter;
+	}
+
+	if (source_filter) {
 		char *filter_arg = xstrdup(name);
 		html("<td class='lines'><pre><code>");
-		cgit_open_filter(ctx.repo->source_filter, filter_arg);
+		cgit_open_filter(source_filter, filter_arg);
 		html_raw(buf, size);
-		cgit_close_filter(ctx.repo->source_filter);
+		cgit_close_filter(source_filter);
 		free(filter_arg);
 		html("</code></pre></td></tr></table>\n");
 		return;
-- 
1.9.1.377.g96e67c8



More information about the CGit mailing list