cgit

commit 792f813d342013124ce40142fef4afee3ff00df3

Author: Tobias Bieniek <Tobias.Bieniek@gmx.de>

ui-log: Add "commit-sort" option for controlling commit ordering

This makes it possible to use strict commit date ordering or strict
topological ordering by passing the corresponding flags to "git log".

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

 cgit.c | 14 ++++++++++++--
 cgit.h | 2 ++
 cgitrc.5.txt | 12 ++++++++++++
 cmd.c | 3 ++-
 shared.c | 1 +
 ui-log.c | 10 +++++++++-
 ui-log.h | 2 +-
 ui-summary.c | 2 +-


diff --git a/cgit.c b/cgit.c
index 35f0da13da2218efff32168b799bcab9e5e68ca3..a97ed69653b36d696c0fd564bfbc4be55f99f2b0 100644
--- a/cgit.c
+++ b/cgit.c
@@ -84,7 +84,12 @@ 	else if (!strcmp(name, "enable-remote-branches"))
 		repo->enable_remote_branches = atoi(value);
 	else if (!strcmp(name, "enable-subject-links"))
 		repo->enable_subject_links = atoi(value);
-	else if (!strcmp(name, "max-stats"))
+	else if (!strcmp(name, "commit-sort")) {
+		if (!strcmp(value, "date"))
+			repo->commit_sort = 1;
+		if (!strcmp(value, "topo"))
+			repo->commit_sort = 2;
+	} else if (!strcmp(name, "max-stats"))
 		repo->max_stats = cgit_find_stats_period(value, NULL);
 	else if (!strcmp(name, "module-link"))
 		repo->module_link= xstrdup(value);
@@ -261,7 +266,12 @@ 	else if (!strcmp(name, "clone-url"))
 		ctx.cfg.clone_url = xstrdup(value);
 	else if (!strcmp(name, "local-time"))
 		ctx.cfg.local_time = atoi(value);
-	else if (!prefixcmp(name, "mimetype."))
+	else if (!strcmp(name, "commit-sort")) {
+		if (!strcmp(value, "date"))
+			ctx.cfg.commit_sort = 1;
+		if (!strcmp(value, "topo"))
+			ctx.cfg.commit_sort = 2;
+	} else if (!prefixcmp(name, "mimetype."))
 		add_mimetype(name + 9, value);
 	else if (!strcmp(name, "include"))
 		parse_configfile(expand_macros(value), config_cb);




diff --git a/cgit.h b/cgit.h
index becf776a3b6d8d45d66338b5a3eb1f9b0c3ab943..7a99135710d9c9ed96fe1eeac4b3dc6500723b3e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -84,6 +84,7 @@ 	int enable_log_linecount;
 	int enable_remote_branches;
 	int enable_subject_links;
 	int max_stats;
+	int commit_sort;
 	time_t mtime;
 	struct cgit_filter *about_filter;
 	struct cgit_filter *commit_filter;
@@ -231,6 +232,7 @@ 	int summary_branches;
 	int summary_log;
 	int summary_tags;
 	int ssdiff;
+	int commit_sort;
 	struct string_list mimetypes;
 	struct cgit_filter *about_filter;
 	struct cgit_filter *commit_filter;




diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 78bb9fc802ab56f50cdeb9cd4e3db928bc9931f1..7d01fcde58fc6fea2dc6af2b8247c4a9c8da7365 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -192,6 +192,12 @@ local-time::
 	Flag which, if set to "1", makes cgit print commit and tag times in the
 	servers timezone. Default value: "0".
 
+commit-sort::
+	Flag which, when set to "date", enables strict date ordering in the
+	commit log, and when set to "topo" enables strict topological
+	ordering. If unset, the default ordering of "git log" is used. Default
+	value: unset.
+
 logo::
 	Url which specifies the source of an image which will be used as a logo
 	on all cgit pages. Default value: "/cgit.png".
@@ -434,6 +440,12 @@
 repo.enable-subject-links::
 	A flag which can be used to override the global setting
 	`enable-subject-links'. Default value: none.
+
+repo.commit-sort::
+	Flag which, when set to "date", enables strict date ordering in the
+	commit log, and when set to "topo" enables strict topological
+	ordering. If unset, the default ordering of "git log" is used. Default
+	value: unset.
 
 repo.logo::
 	Url which specifies the source of an image which will be used as a logo




diff --git a/cmd.c b/cmd.c
index 5a3d1574556e5a09510b891482ef38b22b0ca8a6..899e913b30967d4b4e1d3aa8a770dae148ab60ce 100644
--- a/cmd.c
+++ b/cmd.c
@@ -68,7 +68,8 @@ static void log_fn(struct cgit_context *ctx)
 {
 	cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count,
 		       ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1,
-		       ctx->repo->enable_commit_graph);
+		       ctx->repo->enable_commit_graph,
+		       ctx->repo->commit_sort);
 }
 
 static void ls_cache_fn(struct cgit_context *ctx)




diff --git a/shared.c b/shared.c
index 3e20937a0ce7dbc568742a5d9cef8502d7dde406..8e5ae4811d13f104530e4980967b5dc0d79d3529 100644
--- a/shared.c
+++ b/shared.c
@@ -63,6 +63,7 @@ 	ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
 	ret->enable_remote_branches = ctx.cfg.enable_remote_branches;
 	ret->enable_subject_links = ctx.cfg.enable_subject_links;
 	ret->max_stats = ctx.cfg.max_stats;
+	ret->commit_sort = ctx.cfg.commit_sort;
 	ret->module_link = ctx.cfg.module_link;
 	ret->readme = ctx.cfg.readme;
 	ret->mtime = -1;




diff --git a/ui-log.c b/ui-log.c
index 6b12ca2acb845951be734a964725962f4e67cb93..2f41602a917de13ac9f9daa6cdd50ff15afa3c27 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -278,7 +278,7 @@ 	return result;
 }
 
 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
-		    char *path, int pager, int commit_graph)
+		    char *path, int pager, int commit_graph, int commit_sort)
 {
 	struct rev_info rev;
 	struct commit *commit;
@@ -325,6 +325,14 @@ 		vector_push(&vec, &graph_arg, 0);
 		vector_push(&vec, &color_arg, 0);
 		graph_set_column_colors(column_colors_html,
 					COLUMN_COLORS_HTML_MAX);
+	}
+
+	if (commit_sort == 1) {
+		static const char *date_order_arg = "--date-order";
+		vector_push(&vec, &date_order_arg, 0);
+	} else if (commit_sort == 2) {
+		static const char *topo_order_arg = "--topo-order";
+		vector_push(&vec, &topo_order_arg, 0);
 	}
 
 	if (path) {




diff --git a/ui-log.h b/ui-log.h
index d0cb7790688b2a16cc51284f434f296d6a43ceb3..d324c9284232c3e5ccc1bbcd407fb75551834d3e 100644
--- a/ui-log.h
+++ b/ui-log.h
@@ -3,7 +3,7 @@ #define UI_LOG_H
 
 extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep,
 			   char *pattern, char *path, int pager,
-			   int commit_graph);
+			   int commit_graph, int commit_sort);
 extern void show_commit_decorations(struct commit *commit);
 
 #endif /* UI_LOG_H */




diff --git a/ui-summary.c b/ui-summary.c
index 227ed276d453c951174a815747674f8993f6a337..b4fdd57690ebec764a6394f60ce208dc21faea98 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -59,7 +59,7 @@ 	cgit_print_tags(ctx.cfg.summary_tags);
 	if (ctx.cfg.summary_log > 0) {
 		html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
 		cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
-			       NULL, NULL, 0, 0);
+			       NULL, NULL, 0, 0, 0);
 	}
 	if (ctx.repo->clone_url)
 		print_urls(expand_macros(ctx.repo->clone_url), NULL);