[PATCH 1/6] Implement parsing of new enable-commit-graph option

Kian Kasad kian at kasad.com
Fri Aug 5 04:59:34 UTC 2022


The enable-commit-graph option has been changed from a boolean option to
a string option. It takes the following values:

	"none" or "0":
		Disable the display of commit graphs completely. The
		graph page will be disabled and the log page will not
		show commit graphs.

	"combined" or "1":
		Disable the graph page and show the commit graph on the
		log page. The commit age is still displayed in a
		separate column. This follows the same behavior as
		before when this option was set to "1".

	"separate":
		Enable the graph page and give it its own tab. The graph
		page is the same as the log page except it displays the
		commit graph *instead of* the commit age. The log page
		shows the commit age and not the commit graph.

The "0" and "1" option values should be avoided in new configurations
and only exist for backwards compatibility.
---
 cgit.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/cgit.c b/cgit.c
index 08d81a1..ce7b291 100644
--- a/cgit.c
+++ b/cgit.c
@@ -62,9 +62,14 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
 		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"))
+	else if (!strcmp(name, "enable-commit-graph")) {
+		if (!strcmp(value, "none") || !strcmp(value, "0"))
+			repo->enable_commit_graph = 0;
+		else if (!strcmp(value, "combined") || !strcmp(value, "1"))
+			repo->enable_commit_graph = 1;
+		else if (!strcmp(value, "separate"))
+			repo->enable_commit_graph = 2;
+	} else if (!strcmp(name, "enable-log-filecount"))
 		repo->enable_log_filecount = atoi(value);
 	else if (!strcmp(name, "enable-log-linecount"))
 		repo->enable_log_linecount = atoi(value);
@@ -179,9 +184,14 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.enable_index_owner = atoi(value);
 	else if (!strcmp(name, "enable-blame"))
 		ctx.cfg.enable_blame = atoi(value);
-	else if (!strcmp(name, "enable-commit-graph"))
-		ctx.cfg.enable_commit_graph = atoi(value);
-	else if (!strcmp(name, "enable-log-filecount"))
+	else if (!strcmp(name, "enable-commit-graph")) {
+		if (!strcmp(value, "none") || !strcmp(value, "0"))
+			ctx.cfg.enable_commit_graph = 0;
+		else if (!strcmp(value, "combined") || !strcmp(value, "1"))
+			ctx.cfg.enable_commit_graph = 1;
+		else if (!strcmp(value, "separate"))
+			ctx.cfg.enable_commit_graph = 2;
+	} else if (!strcmp(name, "enable-log-filecount"))
 		ctx.cfg.enable_log_filecount = atoi(value);
 	else if (!strcmp(name, "enable-log-linecount"))
 		ctx.cfg.enable_log_linecount = atoi(value);
@@ -818,8 +828,12 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
 		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);
+	if (repo->enable_commit_graph) {
+		if (repo->enable_commit_graph == 1)
+			fprintf(f, "repo.enable-commit-graph=combined\n");
+		if (repo->enable_commit_graph == 2)
+			fprintf(f, "repo.enable-commit-graph=separate\n");
+	}
 	fprintf(f, "repo.enable-log-filecount=%d\n",
 	        repo->enable_log_filecount);
 	fprintf(f, "repo.enable-log-linecount=%d\n",
-- 
2.37.1



More information about the CGit mailing list