aboutsummaryrefslogtreecommitdiffstats
path: root/ui-repolist.c
diff options
context:
space:
mode:
authorGravatar Jason A. Donenfeld <Jason@zx2c4.com>2012-07-13 02:13:39 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2012-07-13 03:01:46 (JST)
commit184c5655b2e350dbd0dd8be75d3f370f22aa6dee (patch)
treebcd4fef53e416f443666ec50f21adef33fc95e76 /ui-repolist.c
parentfc9181ff3d3ebbe0159871f6a49438e60bb17f58 (diff)
downloadcgit-184c5655b2e350dbd0dd8be75d3f370f22aa6dee.zip
cgit-184c5655b2e350dbd0dd8be75d3f370f22aa6dee.tar.gz
ui-repolist: Case insensitive sorting and age sort
Add two options, one for doing the ordinary name sorts in a case-insensitive manner, and another for choosing to sort repos in each section by age instead of by name.
Diffstat (limited to 'ui-repolist.c')
-rw-r--r--ui-repolist.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/ui-repolist.c b/ui-repolist.c
index d946f32..4e2bdf4 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -9,6 +9,7 @@
9#include "cgit.h" 9#include "cgit.h"
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12#include <strings.h>
12 13
13time_t read_agefile(char *path) 14time_t read_agefile(char *path)
14{ 15{
@@ -131,8 +132,12 @@ void print_pager(int items, int pagelen, char *search, char *sort)
131 132
132static int cmp(const char *s1, const char *s2) 133static int cmp(const char *s1, const char *s2)
133{ 134{
134 if (s1 && s2) 135 if (s1 && s2) {
135 return strcmp(s1, s2); 136 if (ctx.cfg.case_sensitive_sort)
137 return strcmp(s1, s2);
138 else
139 return strcasecmp(s1, s2);
140 }
136 if (s1 && !s2) 141 if (s1 && !s2)
137 return -1; 142 return -1;
138 if (s2 && !s1) 143 if (s2 && !s1)
@@ -145,10 +150,19 @@ static int sort_section(const void *a, const void *b)
145 const struct cgit_repo *r1 = a; 150 const struct cgit_repo *r1 = a;
146 const struct cgit_repo *r2 = b; 151 const struct cgit_repo *r2 = b;
147 int result; 152 int result;
153 time_t t;
148 154
149 result = cmp(r1->section, r2->section); 155 result = cmp(r1->section, r2->section);
150 if (!result) 156 if (!result) {
151 result = cmp(r1->name, r2->name); 157 if (!strcmp(ctx.cfg.section_sort, "age")) {
158 // get_repo_modtime caches the value in r->mtime, so we don't
159 // have to worry about inefficiencies here.
160 if (get_repo_modtime(r1, &t) && get_repo_modtime(r2, &t))
161 result = r2->mtime - r1->mtime;
162 }
163 if (!result)
164 result = cmp(r1->name, r2->name);
165 }
152 return result; 166 return result;
153} 167}
154 168