about summary refs log tree commit diff stats
path: root/ui-repolist.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-repolist.c')
-rw-r--r--ui-repolist.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index 3aedde5..3ef2e99 100644 --- a/ui-repolist.c +++ b/ui-repolist.c
@@ -18,19 +18,20 @@
18 18
19time_t read_agefile(char *path) 19time_t read_agefile(char *path)
20{ 20{
21 FILE *f; 21 time_t result;
22 static char buf[64], buf2[64]; 22 size_t size;
23 char *buf;
24 static char buf2[64];
23 25
24 if (!(f = fopen(path, "r"))) 26 if (readfile(path, &buf, &size))
25 return -1; 27 return -1;
26 buf[0] = 0; 28
27 if (fgets(buf, sizeof(buf), f) == NULL)
28 return -1;
29 fclose(f);
30 if (parse_date(buf, buf2, sizeof(buf2))) 29 if (parse_date(buf, buf2, sizeof(buf2)))
31 return strtoul(buf2, NULL, 10); 30 result = strtoul(buf2, NULL, 10);
32 else 31 else
33 return 0; 32 result = 0;
33 free(buf);
34 return result;
34} 35}
35 36
36static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) 37static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
@@ -135,6 +136,18 @@ static int cmp(const char *s1, const char *s2)
135 return 0; 136 return 0;
136} 137}
137 138
139static int sort_section(const void *a, const void *b)
140{
141 const struct cgit_repo *r1 = a;
142 const struct cgit_repo *r2 = b;
143 int result;
144
145 result = cmp(r1->section, r2->section);
146 if (!result)
147 result = cmp(r1->name, r2->name);
148 return result;
149}
150
138static int sort_name(const void *a, const void *b) 151static int sort_name(const void *a, const void *b)
139{ 152{
140 const struct cgit_repo *r1 = a; 153 const struct cgit_repo *r1 = a;
@@ -177,6 +190,7 @@ struct sortcolumn {
177}; 190};
178 191
179struct sortcolumn sortcolumn[] = { 192struct sortcolumn sortcolumn[] = {
193 {"section", sort_section},
180 {"name", sort_name}, 194 {"name", sort_name},
181 {"desc", sort_desc}, 195 {"desc", sort_desc},
182 {"owner", sort_owner}, 196 {"owner", sort_owner},
@@ -202,7 +216,8 @@ int sort_repolist(char *field)
202void cgit_print_repolist() 216void cgit_print_repolist()
203{ 217{
204 int i, columns = 4, hits = 0, header = 0; 218 int i, columns = 4, hits = 0, header = 0;
205 char *last_group = NULL; 219 char *last_section = NULL;
220 char *section;
206 int sorted = 0; 221 int sorted = 0;
207 222
208 if (ctx.cfg.enable_index_links) 223 if (ctx.cfg.enable_index_links)
@@ -218,6 +233,8 @@ void cgit_print_repolist()
218 233
219 if(ctx.qry.sort) 234 if(ctx.qry.sort)
220 sorted = sort_repolist(ctx.qry.sort); 235 sorted = sort_repolist(ctx.qry.sort);
236 else
237 sort_repolist("section");
221 238
222 html("<table summary='repository list' class='list nowrap'>"); 239 html("<table summary='repository list' class='list nowrap'>");
223 for (i=0; i<cgit_repolist.count; i++) { 240 for (i=0; i<cgit_repolist.count; i++) {
@@ -231,19 +248,22 @@ void cgit_print_repolist()
231 continue; 248 continue;
232 if (!header++) 249 if (!header++)
233 print_header(columns); 250 print_header(columns);
251 section = ctx.repo->section;
252 if (section && !strcmp(section, ""))
253 section = NULL;
234 if (!sorted && 254 if (!sorted &&
235 ((last_group == NULL && ctx.repo->group != NULL) || 255 ((last_section == NULL && section != NULL) ||
236 (last_group != NULL && ctx.repo->group == NULL) || 256 (last_section != NULL && section == NULL) ||
237 (last_group != NULL && ctx.repo->group != NULL && 257 (last_section != NULL && section != NULL &&
238 strcmp(ctx.repo->group, last_group)))) { 258 strcmp(section, last_section)))) {
239 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", 259 htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
240 columns); 260 columns);
241 html_txt(ctx.repo->group); 261 html_txt(section);
242 html("</td></tr>"); 262 html("</td></tr>");
243 last_group = ctx.repo->group; 263 last_section = section;
244 } 264 }
245 htmlf("<tr><td class='%s'>", 265 htmlf("<tr><td class='%s'>",
246 !sorted && ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); 266 !sorted && section ? "sublevel-repo" : "toplevel-repo");
247 cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); 267 cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
248 html("</td><td>"); 268 html("</td><td>");
249 html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); 269 html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
@@ -274,6 +294,11 @@ void cgit_print_repolist()
274 294
275void cgit_print_site_readme() 295void cgit_print_site_readme()
276{ 296{
277 if (ctx.cfg.root_readme) 297 if (!ctx.cfg.root_readme)
278 html_include(ctx.cfg.root_readme); 298 return;
299 if (ctx.cfg.about_filter)
300 cgit_open_filter(ctx.cfg.about_filter);
301 html_include(ctx.cfg.root_readme);
302 if (ctx.cfg.about_filter)
303 cgit_close_filter(ctx.cfg.about_filter);
279} 304}