From 389cc17357e2040c9542d3e085f64a8d2f085e9a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 8 Apr 2013 16:57:12 +0200 Subject: 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 --- cgit.c | 14 +++++++++++++- cgit.h | 2 ++ cgitrc.5.txt | 46 ++++++++++++++++++++++++++++------------------ shared.c | 1 + ui-refs.c | 5 ++--- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/cgit.c b/cgit.c index 4dadd97..6f44ef2 100644 --- a/cgit.c +++ b/cgit.c @@ -84,7 +84,12 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va 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 @@ static void config_cb(const char *name, const char *value) 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 @@ static void prepare_context(struct cgit_context *ctx) 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 3e9d55b..850b792 100644 --- a/cgit.h +++ b/cgit.h @@ -85,6 +85,7 @@ struct cgit_repo { 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 @@ struct cgit_config { 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 4d27d9f..39b031e 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -40,6 +40,11 @@ agefile:: 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". @@ -92,6 +97,12 @@ commit-filter:: 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. Default value: "/cgit.css". @@ -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". @@ -299,6 +304,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: "index, nofollow". @@ -339,12 +350,6 @@ section:: 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". @@ -417,6 +427,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 exists in the repository, the first branch name (when sorted) is used @@ -446,12 +462,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 on this repo's pages. Default value: global logo. diff --git a/shared.c b/shared.c index 10be355..4369378 100644 --- a/shared.c +++ b/shared.c @@ -63,6 +63,7 @@ struct cgit_repo *cgit_add_repo(const char *url) 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 3fbaad0..0ae0612 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -197,10 +197,9 @@ void cgit_print_branches(int maxcount) 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]); -- cgit 1.3.0-6-gf8a5