cgit

commit e1ad15d368bdeb1bffea588b93a29055c5dfb7f4

Author: Christian Hesse <mail@eworm.de>

ui-tree: allow per repository override for enable-blame

The blame operation can cause high cost in terms of CPU load for huge
repositories. Let's add a per repository override for enable-blame.

Signed-off-by: Christian Hesse <mail@eworm.de>

 cgit.c | 4 ++++
 cgit.h | 1 +
 cgitrc.5.txt | 4 ++++
 cmd.c | 2 +-
 shared.c | 1 +
 ui-tree.c | 4 ++--


diff --git a/cgit.c b/cgit.c
index 2f07e6d5c88ddb9a9647da519d5044513f39a5e4..2910d4b861d76df28b14f6712d30e3568f4ab65b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -50,6 +50,8 @@ 	else if (!strcmp(name, "extra-head-content"))
 		repo->extra_head_content = xstrdup(value);
 	else if (!strcmp(name, "snapshots"))
 		repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
+	else if (!strcmp(name, "enable-blame"))
+		repo->enable_blame = atoi(value);
 	else if (!strcmp(name, "enable-commit-graph"))
 		repo->enable_commit_graph = atoi(value);
 	else if (!strcmp(name, "enable-log-filecount"))
@@ -809,6 +811,8 @@ 	if (repo->homepage)
 		fprintf(f, "repo.homepage=%s\n", repo->homepage);
 	if (repo->clone_url)
 		fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
+	fprintf(f, "repo.enable-blame=%d\n",
+	        repo->enable_blame);
 	fprintf(f, "repo.enable-commit-graph=%d\n",
 	        repo->enable_commit_graph);
 	fprintf(f, "repo.enable-log-filecount=%d\n",




diff --git a/cgit.h b/cgit.h
index bcc4fce3d6d1f0d891b1dd95c1f353a657f4f098..7ec46b48464039a8b94393df5d6ce3fabca3e6ab 100644
--- a/cgit.h
+++ b/cgit.h
@@ -94,6 +94,7 @@ 	char *logo;
 	char *logo_link;
 	char *snapshot_prefix;
 	int snapshots;
+	int enable_blame;
 	int enable_commit_graph;
 	int enable_log_filecount;
 	int enable_log_linecount;




diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 34b351b00ffc1006966612ce957cbd4b134a5b72..ba77826fd0c23d54bbf990f9251e0b7f27c3a602 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -485,6 +485,10 @@ repo.email-filter::
 	Override the default email-filter. Default value: none. See also:
 	"enable-filter-overrides". See also: "FILTER API".
 
+repo.enable-blame::
+	A flag which can be used to disable the global setting
+	`enable-blame'. Default value: none.
+
 repo.enable-commit-graph::
 	A flag which can be used to disable the global setting
 	`enable-commit-graph'. Default value: none.




diff --git a/cmd.c b/cmd.c
index 63f0ae54695bfb714fbdd2f150751baab6b5bf44..bf6d8f516fe0263aa50a5b13348f39befabe01e4 100644
--- a/cmd.c
+++ b/cmd.c
@@ -66,7 +66,7 @@ }
 
 static void blame_fn(void)
 {
-	if (ctx.cfg.enable_blame)
+	if (ctx.repo->enable_blame)
 		cgit_print_blame();
 	else
 		cgit_print_error_page(403, "Forbidden", "Blame is disabled");




diff --git a/shared.c b/shared.c
index a2c0d038165cd87f09329fc75117183bfca86d24..8115469a7cec4280e6bf4ccccf73563a5807568d 100644
--- a/shared.c
+++ b/shared.c
@@ -58,6 +58,7 @@ 	ret->owner = NULL;
 	ret->homepage = NULL;
 	ret->section = ctx.cfg.section;
 	ret->snapshots = ctx.cfg.snapshots;
+	ret->enable_blame = ctx.cfg.enable_blame;
 	ret->enable_commit_graph = ctx.cfg.enable_commit_graph;
 	ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
 	ret->enable_log_linecount = ctx.cfg.enable_log_linecount;




diff --git a/ui-tree.c b/ui-tree.c
index 4be89c8e7fcbf7ac68cca848a86a438f6c3e1235..84eb17d6470d718dd99fbe9eb5636967bbaf2226 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -110,7 +110,7 @@ 	cgit_print_layout_start();
 	htmlf("blob: %s (", oid_to_hex(oid));
 	cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
 		        rev, path);
-	if (ctx.cfg.enable_blame) {
+	if (ctx.repo->enable_blame) {
 		html(") (");
 		cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
 			        rev, path);
@@ -251,7 +251,7 @@ 				fullpath.buf);
 	if (!S_ISGITLINK(mode))
 		cgit_plain_link("plain", NULL, "button", ctx.qry.head,
 				walk_tree_ctx->curr_rev, fullpath.buf);
-	if (!S_ISDIR(mode) && ctx.cfg.enable_blame)
+	if (!S_ISDIR(mode) && ctx.repo->enable_blame)
 		cgit_blame_link("blame", NULL, "button", ctx.qry.head,
 				walk_tree_ctx->curr_rev, fullpath.buf);
 	html("</td></tr>\n");