[PATCH 4/4] ui-blame: put source lines through filter

Jason A. Donenfeld Jason at zx2c4.com
Sat Oct 14 16:17:50 CEST 2017


We toggle the filter on and off so that the control table can avoid
going through the filter.

Signed-off-by: Jason A. Donenfeld <Jason at zx2c4.com>
---
 ui-blame.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/ui-blame.c b/ui-blame.c
index 62cf431..71aec65 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -70,7 +70,12 @@ static void emit_blame_entry(struct blame_scoreboard *sb,
 	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
 
 	html("<td class='lines'><pre><code>");
-	html_ntxt(cp, cpend - cp);
+	if (ctx.repo->source_filter) {
+		cgit_enable_filter(ctx.repo->source_filter, true);
+		html_raw(cp, cpend - cp);
+		cgit_enable_filter(ctx.repo->source_filter, false);
+	} else
+		html_ntxt(cp, cpend - cp);
 	html("</code></pre></td></tr>\n");
 }
 
@@ -90,6 +95,7 @@ static void print_object(const unsigned char *sha1, const char *path,
 	struct blame_scoreboard sb;
 	struct blame_origin *o;
 	struct blame_entry *ent = NULL;
+	char *filter_arg;
 
 	type = sha1_object_info(sha1, &size);
 	if (type == OBJ_BAD) {
@@ -131,6 +137,11 @@ static void print_object(const unsigned char *sha1, const char *path,
 		return;
 	}
 
+	if (ctx.repo->source_filter) {
+		filter_arg = xstrdup(path);
+		cgit_open_filter(ctx.repo->source_filter, filter_arg);
+		cgit_enable_filter(ctx.repo->source_filter, false);
+	}
 	html("<table class='blame blob'>");
 	for (ent = sb.ent; ent; ) {
 		struct blame_entry *e = ent->next;
@@ -139,6 +150,8 @@ static void print_object(const unsigned char *sha1, const char *path,
 		ent = e;
 	}
 	html("</table>\n");
+	if (ctx.repo->source_filter)
+		cgit_close_filter(ctx.repo->source_filter);
 	free((void *)sb.final_buf);
 
 	cgit_print_layout_end();
-- 
2.14.2



More information about the CGit mailing list