cgit

commit 389cc17357e2040c9542d3e085f64a8d2f085e9a

Author: Jason A. Donenfeld <Jason@zx2c4.com>

Add branch-sort and repo.branch-sort options.

When set to "name", branches are sorted by name, which is the current
default. When set to "age", branches are sorted by the age of the
repository.

This feature was requested by Konstantin Ryabitsev for use on
kernel.org.

Proposed-by: Konstantin Ryabitsev <mricon@kernel.org>

 cgit.c | 14 +++++++++++++-
 cgit.h | 2 ++
 cgitrc.5.txt | 46 ++++++++++++++++++++++++++++------------------
 shared.c | 1 +
 ui-refs.c | 5 ++---


diff --git a/cgit.c b/cgit.c
index 4dadd97e3d7dbfda597771f26d7e9b4c510c463f..6f44ef2691329881de407d5e577c8d6d84c7dfca 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, "commit-sort")) {
+	else if (!strcmp(name, "branch-sort")) {
+		if (!strcmp(value, "age"))
+			repo->branch_sort = 1;
+		if (!strcmp(value, "name"))
+			repo->branch_sort = 0;
+	} else if (!strcmp(name, "commit-sort")) {
 		if (!strcmp(value, "date"))
 			repo->commit_sort = 1;
 		if (!strcmp(value, "topo"))
@@ -271,6 +276,11 @@ 		if (!strcmp(value, "date"))
 			ctx.cfg.commit_sort = 1;
 		if (!strcmp(value, "topo"))
 			ctx.cfg.commit_sort = 2;
+	} else if (!strcmp(name, "branch-sort")) {
+		if (!strcmp(value, "age"))
+			ctx.cfg.branch_sort = 1;
+		if (!strcmp(value, "name"))
+			ctx.cfg.branch_sort = 0;
 	} else if (!prefixcmp(name, "mimetype."))
 		add_mimetype(name + 9, value);
 	else if (!strcmp(name, "include"))
@@ -345,6 +355,8 @@ 	ctx->cfg.cache_root_ttl = 5;
 	ctx->cfg.cache_scanrc_ttl = 15;
 	ctx->cfg.cache_static_ttl = -1;
 	ctx->cfg.case_sensitive_sort = 1;
+	ctx->cfg.branch_sort = 0;
+	ctx->cfg.commit_sort = 0;
 	ctx->cfg.css = "/cgit.css";
 	ctx->cfg.logo = "/cgit.png";
 	ctx->cfg.local_time = 0;




diff --git a/cgit.h b/cgit.h
index 3e9d55bec6418ceac8e768ba919b3d66b91dd209..850b7925b374ca37f05a9c86e84e47ed3acbdab8 100644
--- a/cgit.h
+++ b/cgit.h
@@ -85,6 +85,7 @@ 	int enable_log_linecount;
 	int enable_remote_branches;
 	int enable_subject_links;
 	int max_stats;
+	int branch_sort;
 	int commit_sort;
 	time_t mtime;
 	struct cgit_filter *about_filter;
@@ -234,6 +235,7 @@ 	int summary_branches;
 	int summary_log;
 	int summary_tags;
 	int ssdiff;
+	int branch_sort;
 	int commit_sort;
 	struct string_list mimetypes;
 	struct cgit_filter *about_filter;




diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 4d27d9ff6a810aaa5d109295e8e89e40344edc64..39b031eacaa56337508c9f4ab84cb1fd12fb356b 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -40,6 +40,11 @@ 	The first line in the file is used as input to the "parse_date"
 	function in libgit. Recommended timestamp-format is "yyyy-mm-dd
 	hh:mm:ss". Default value: "info/web/last-modified".
 
+branch-sort::
+	Flag which, when set to "age", enables date ordering in the branch ref
+	list, and when set to "name" enables ordering by branch name. Default
+	value: "name".
+
 cache-root::
 	Path used to store the cgit cache entries. Default value:
 	"/var/cache/cgit". See also: "MACRO EXPANSION".
@@ -91,6 +96,12 @@ 	The command will get the message on its STDIN, and the STDOUT from the
 	command will be included verbatim as the commit message, i.e. this can
 	be used to implement bugtracker integration. Default value: none.
 	See also: "FILTER API".
+
+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.
 
 css::
 	Url which specifies the css document to include in all cgit pages.
@@ -196,12 +207,6 @@ 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".
@@ -298,6 +303,12 @@
 repo.group::
 	Legacy alias for "section". This option is deprecated and will not be
 	supported in cgit-1.0.
+
+repository-sort::
+	The way in which repositories in each section are sorted. Valid values
+	are "name" for sorting by the repo name or "age" for sorting by the
+	most recently updated repository. Default value: "name". See also:
+	section, case-sensitive-sort, section-sort.
 
 robots::
 	Text used as content for the "robots" meta-tag. Default value:
@@ -339,12 +350,6 @@ 	The name of the current repository section - all repositories defined
 	after this option will inherit the current section name. Default value:
 	none.
 
-repository-sort::
-	The way in which repositories in each section are sorted. Valid values
-	are "name" for sorting by the repo name or "age" for sorting by the
-	most recently updated repository. Default value: "name". See also:
-	section, case-sensitive-sort, section-sort.
-
 section-sort::
 	Flag which, when set to "1", will sort the sections on the repository
 	listing by name. Set this flag to "0" if the order in the cgitrc file should
@@ -409,6 +414,11 @@ repo.about-filter::
 	Override the default about-filter. Default value: none. See also:
 	"enable-filter-overrides". See also: "FILTER API".
 
+repo.branch-sort::
+	Flag which, when set to "age", enables date ordering in the branch ref
+	list, and when set to "name" enables ordering by branch name. Default
+	value: "name".
+
 repo.clone-url::
 	A list of space-separated urls which can be used to clone this repo.
 	Default value: none. See also: "MACRO EXPANSION".
@@ -416,6 +426,12 @@
 repo.commit-filter::
 	Override the default commit-filter. Default value: none. See also:
 	"enable-filter-overrides". See also: "FILTER API".
+
+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.defbranch::
 	The name of the default branch for this repository. If no such branch
@@ -445,12 +461,6 @@
 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/shared.c b/shared.c
index 10be35504dd7f110ef2f6db08dd47da08b81424e..4369378ce2f2aaf45f7b219ff15cdabc47036d6d 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->branch_sort = ctx.cfg.branch_sort;
 	ret->commit_sort = ctx.cfg.commit_sort;
 	ret->module_link = ctx.cfg.module_link;
 	ret->readme = ctx.cfg.readme;




diff --git a/ui-refs.c b/ui-refs.c
index 3fbaad07302d90e1cb127666c51deceb67f5c02d..0ae0612665e95c3254aa6a3ed769f5f355cf5b12 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -197,10 +197,9 @@
 	if (maxcount == 0 || maxcount > list.count)
 		maxcount = list.count;
 
-	if (maxcount < list.count) {
-		qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
+	qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
+	if (ctx.repo->branch_sort == 0)
 		qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
-	}
 
 	for (i = 0; i < maxcount; i++)
 		print_branch(list.refs[i]);