summaryrefslogtreecommitdiffabout
path: root/ui-repolist.c
Unidiff
Diffstat (limited to 'ui-repolist.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-repolist.c63
1 files changed, 44 insertions, 19 deletions
diff --git a/ui-repolist.c b/ui-repolist.c
index 3aedde5..3ef2e99 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -13,29 +13,30 @@
13#include <time.h> 13#include <time.h>
14 14
15#include "cgit.h" 15#include "cgit.h"
16#include "html.h" 16#include "html.h"
17#include "ui-shared.h" 17#include "ui-shared.h"
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)
37{ 38{
38 char *path; 39 char *path;
39 struct stat s; 40 struct stat s;
40 struct cgit_repo *r = (struct cgit_repo *)repo; 41 struct cgit_repo *r = (struct cgit_repo *)repo;
41 42
@@ -130,16 +131,28 @@ static int cmp(const char *s1, const char *s2)
130 return strcmp(s1, s2); 131 return strcmp(s1, s2);
131 if (s1 && !s2) 132 if (s1 && !s2)
132 return -1; 133 return -1;
133 if (s2 && !s1) 134 if (s2 && !s1)
134 return 1; 135 return 1;
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;
141 const struct cgit_repo *r2 = b; 154 const struct cgit_repo *r2 = b;
142 155
143 return cmp(r1->name, r2->name); 156 return cmp(r1->name, r2->name);
144} 157}
145 158
@@ -172,16 +185,17 @@ static int sort_idle(const void *a, const void *b)
172} 185}
173 186
174struct sortcolumn { 187struct sortcolumn {
175 const char *name; 188 const char *name;
176 int (*fn)(const void *a, const void *b); 189 int (*fn)(const void *a, const void *b);
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},
183 {"idle", sort_idle}, 197 {"idle", sort_idle},
184 {NULL, NULL} 198 {NULL, NULL}
185}; 199};
186 200
187int sort_repolist(char *field) 201int sort_repolist(char *field)
@@ -197,58 +211,64 @@ int sort_repolist(char *field)
197 } 211 }
198 return 0; 212 return 0;
199} 213}
200 214
201 215
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)
209 columns++; 224 columns++;
210 225
211 ctx.page.title = ctx.cfg.root_title; 226 ctx.page.title = ctx.cfg.root_title;
212 cgit_print_http_headers(&ctx); 227 cgit_print_http_headers(&ctx);
213 cgit_print_docstart(&ctx); 228 cgit_print_docstart(&ctx);
214 cgit_print_pageheader(&ctx); 229 cgit_print_pageheader(&ctx);
215 230
216 if (ctx.cfg.index_header) 231 if (ctx.cfg.index_header)
217 html_include(ctx.cfg.index_header); 232 html_include(ctx.cfg.index_header);
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++) {
224 ctx.repo = &cgit_repolist.repos[i]; 241 ctx.repo = &cgit_repolist.repos[i];
225 if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) 242 if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
226 continue; 243 continue;
227 hits++; 244 hits++;
228 if (hits <= ctx.qry.ofs) 245 if (hits <= ctx.qry.ofs)
229 continue; 246 continue;
230 if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) 247 if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
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);
250 html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); 270 html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
251 html_link_close(); 271 html_link_close();
252 html("</td><td>"); 272 html("</td><td>");
253 html_txt(ctx.repo->owner); 273 html_txt(ctx.repo->owner);
254 html("</td><td>"); 274 html("</td><td>");
@@ -269,11 +289,16 @@ void cgit_print_repolist()
269 cgit_print_error("No repositories found"); 289 cgit_print_error("No repositories found");
270 else if (hits > ctx.cfg.max_repo_count) 290 else if (hits > ctx.cfg.max_repo_count)
271 print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search); 291 print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search);
272 cgit_print_docend(); 292 cgit_print_docend();
273} 293}
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)
298 return;
299 if (ctx.cfg.about_filter)
300 cgit_open_filter(ctx.cfg.about_filter);
278 html_include(ctx.cfg.root_readme); 301 html_include(ctx.cfg.root_readme);
302 if (ctx.cfg.about_filter)
303 cgit_close_filter(ctx.cfg.about_filter);
279} 304}