aboutsummaryrefslogtreecommitdiff
path: root/development/cgit/sort-summary-branches.patch
blob: 2b1d96c6932c44a8f03bd136d97afba5121bfedb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
When there are more than `summary-branches` in a repo, the summary page
trimmed the list by age and then sorted them by name.  Make sorting by
name optional, though keep it as the default.

Signed-off-by: Todd Zullinger <tmz at pobox.com>
---
This was requested by a friend for whom I setup cgit.  I don't know if
it's a worthwhile option or not.  It's handy for me to avoid having to
patch that install.  Beware, my C is weak.  If there are egregious
errors in style or content, I won't be shocked or offended to hear
about them.

 cgit.c       |    3 +++
 cgit.h       |    1 +
 cgitrc.5.txt |    5 +++++
 ui-refs.c    |    4 +++-
 4 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/cgit.c b/cgit.c
index e302a7c..ebbcad1 100644
--- a/cgit.c
+++ b/cgit.c
@@ -233,6 +233,8 @@ void config_cb(const char *name, const char *value)
 		ctx.cfg.local_time = atoi(value);
 	else if (!prefixcmp(name, "mimetype."))
 		add_mimetype(name + 9, value);
+	else if (!strcmp(name, "summary-branches-sort"))
+		ctx.cfg.summary_branches_sort = xstrdup(value);
 	else if (!strcmp(name, "include"))
 		parse_configfile(expand_macros(value), config_cb);
 }
@@ -331,6 +333,7 @@ static void prepare_context(struct cgit_context *ctx)
 	ctx->cfg.script_name = CGIT_SCRIPT_NAME;
 	ctx->cfg.section = "";
 	ctx->cfg.summary_branches = 10;
+	ctx->cfg.summary_branches_sort = "name";
 	ctx->cfg.summary_log = 10;
 	ctx->cfg.summary_tags = 10;
 	ctx->cfg.max_atom_items = 10;
diff --git a/cgit.h b/cgit.h
index b5f00fc..2f847a1 100644
--- a/cgit.h
+++ b/cgit.h
@@ -216,6 +216,7 @@ struct cgit_config {
 	int section_from_path;
 	int snapshots;
 	int summary_branches;
+	char *summary_branches_sort;
 	int summary_log;
 	int summary_tags;
 	int ssdiff;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 65b210f..1c8574b 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -324,6 +324,11 @@ summary-branches::
 	Specifies the number of branches to display in the repository "summary"
 	view. Default value: "10".
 
+summary-branches-sort::
+	Specifies the sort order to use for branches on the summary page, when
+	there are more than `summary-count` branches. Valid options are "name"
+	and "age".  Default value: "name".
+
 summary-log::
 	Specifies the number of log entries to display in the repository
 	"summary" view. Default value: "10".
diff --git a/ui-refs.c b/ui-refs.c
index caddfbc..188e63d 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -197,7 +197,9 @@ void cgit_print_branches(int maxcount)
 
 	if (maxcount < list.count) {
 		qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
-		qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
+		if (ctx.cfg.summary_branches_sort &&
+		    !strcmp(ctx.cfg.summary_branches_sort, "name"))
+			qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
 	}
 
 	for(i=0; i<maxcount; i++)