slackbuilds_ponce/development/cgit/sort-summary-branches.patch
ponce b5d9003dbe development/cgit: Updated for version 20120318_f50be7f.
Signed-off-by: dsomero <xgizzmo@slackbuilds.org>
2012-06-30 12:04:35 -04:00

82 lines
2.8 KiB
Diff

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++)