-rw-r--r-- | ui-repolist.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index 3e97ca9..eeeaf3d 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,110 +1,114 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | ||
10 | #include <time.h> | 9 | #include <time.h> |
11 | 10 | ||
11 | #include "cgit.h" | ||
12 | #include "html.h" | ||
13 | #include "ui-shared.h" | ||
12 | 14 | ||
13 | time_t read_agefile(char *path) | 15 | time_t read_agefile(char *path) |
14 | { | 16 | { |
15 | FILE *f; | 17 | FILE *f; |
16 | static char buf[64], buf2[64]; | 18 | static char buf[64], buf2[64]; |
17 | 19 | ||
18 | if (!(f = fopen(path, "r"))) | 20 | if (!(f = fopen(path, "r"))) |
19 | return -1; | 21 | return -1; |
20 | fgets(buf, sizeof(buf), f); | 22 | fgets(buf, sizeof(buf), f); |
21 | fclose(f); | 23 | fclose(f); |
22 | if (parse_date(buf, buf2, sizeof(buf2))) | 24 | if (parse_date(buf, buf2, sizeof(buf2))) |
23 | return strtoul(buf2, NULL, 10); | 25 | return strtoul(buf2, NULL, 10); |
24 | else | 26 | else |
25 | return 0; | 27 | return 0; |
26 | } | 28 | } |
27 | 29 | ||
28 | static void print_modtime(struct repoinfo *repo) | 30 | static void print_modtime(struct cgit_repo *repo) |
29 | { | 31 | { |
30 | char *path; | 32 | char *path; |
31 | struct stat s; | 33 | struct stat s; |
32 | 34 | ||
33 | path = fmt("%s/%s", repo->path, cgit_agefile); | 35 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
34 | if (stat(path, &s) == 0) { | 36 | if (stat(path, &s) == 0) { |
35 | cgit_print_age(read_agefile(path), -1, NULL); | 37 | cgit_print_age(read_agefile(path), -1, NULL); |
36 | return; | 38 | return; |
37 | } | 39 | } |
38 | 40 | ||
39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 41 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
40 | if (stat(path, &s) != 0) | 42 | if (stat(path, &s) != 0) |
41 | return; | 43 | return; |
42 | cgit_print_age(s.st_mtime, -1, NULL); | 44 | cgit_print_age(s.st_mtime, -1, NULL); |
43 | } | 45 | } |
44 | 46 | ||
45 | void cgit_print_repolist(struct cacheitem *item) | 47 | void cgit_print_repolist() |
46 | { | 48 | { |
47 | int i, columns = 4; | 49 | int i, columns = 4; |
48 | char *last_group = NULL; | 50 | char *last_group = NULL; |
49 | 51 | ||
50 | if (cgit_enable_index_links) | 52 | if (ctx.cfg.enable_index_links) |
51 | columns++; | 53 | columns++; |
52 | 54 | ||
53 | cgit_print_docstart(cgit_root_title, item); | 55 | ctx.page.title = ctx.cfg.root_title; |
54 | cgit_print_pageheader(cgit_root_title, 0); | 56 | cgit_print_http_headers(&ctx); |
57 | cgit_print_docstart(&ctx); | ||
58 | cgit_print_pageheader(&ctx); | ||
55 | 59 | ||
56 | html("<table summary='repository list' class='list nowrap'>"); | 60 | html("<table summary='repository list' class='list nowrap'>"); |
57 | if (cgit_index_header) { | 61 | if (ctx.cfg.index_header) { |
58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", | 62 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
59 | columns); | 63 | columns); |
60 | html_include(cgit_index_header); | 64 | html_include(ctx.cfg.index_header); |
61 | html("</td></tr>"); | 65 | html("</td></tr>"); |
62 | } | 66 | } |
63 | html("<tr class='nohover'>" | 67 | html("<tr class='nohover'>" |
64 | "<th class='left'>Name</th>" | 68 | "<th class='left'>Name</th>" |
65 | "<th class='left'>Description</th>" | 69 | "<th class='left'>Description</th>" |
66 | "<th class='left'>Owner</th>" | 70 | "<th class='left'>Owner</th>" |
67 | "<th class='left'>Idle</th>"); | 71 | "<th class='left'>Idle</th>"); |
68 | if (cgit_enable_index_links) | 72 | if (ctx.cfg.enable_index_links) |
69 | html("<th>Links</th>"); | 73 | html("<th>Links</th>"); |
70 | html("</tr>\n"); | 74 | html("</tr>\n"); |
71 | 75 | ||
72 | for (i=0; i<cgit_repolist.count; i++) { | 76 | for (i=0; i<cgit_repolist.count; i++) { |
73 | cgit_repo = &cgit_repolist.repos[i]; | 77 | ctx.repo = &cgit_repolist.repos[i]; |
74 | if ((last_group == NULL && cgit_repo->group != NULL) || | 78 | if ((last_group == NULL && ctx.repo->group != NULL) || |
75 | (last_group != NULL && cgit_repo->group == NULL) || | 79 | (last_group != NULL && ctx.repo->group == NULL) || |
76 | (last_group != NULL && cgit_repo->group != NULL && | 80 | (last_group != NULL && ctx.repo->group != NULL && |
77 | strcmp(cgit_repo->group, last_group))) { | 81 | strcmp(ctx.repo->group, last_group))) { |
78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 82 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
79 | columns); | 83 | columns); |
80 | html_txt(cgit_repo->group); | 84 | html_txt(ctx.repo->group); |
81 | html("</td></tr>"); | 85 | html("</td></tr>"); |
82 | last_group = cgit_repo->group; | 86 | last_group = ctx.repo->group; |
83 | } | 87 | } |
84 | htmlf("<tr><td class='%s'>", | 88 | htmlf("<tr><td class='%s'>", |
85 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); | 89 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); |
86 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); | 90 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); |
87 | html_txt(cgit_repo->name); | 91 | html_txt(ctx.repo->name); |
88 | html_link_close(); | 92 | html_link_close(); |
89 | html("</td><td>"); | 93 | html("</td><td>"); |
90 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); | 94 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); |
91 | html("</td><td>"); | 95 | html("</td><td>"); |
92 | html_txt(cgit_repo->owner); | 96 | html_txt(ctx.repo->owner); |
93 | html("</td><td>"); | 97 | html("</td><td>"); |
94 | print_modtime(cgit_repo); | 98 | print_modtime(ctx.repo); |
95 | html("</td>"); | 99 | html("</td>"); |
96 | if (cgit_enable_index_links) { | 100 | if (ctx.cfg.enable_index_links) { |
97 | html("<td>"); | 101 | html("<td>"); |
98 | html_link_open(cgit_repourl(cgit_repo->url), | 102 | html_link_open(cgit_repourl(ctx.repo->url), |
99 | NULL, "button"); | 103 | NULL, "button"); |
100 | html("summary</a>"); | 104 | html("summary</a>"); |
101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, | 105 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, |
102 | 0, NULL, NULL); | 106 | 0, NULL, NULL); |
103 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); | 107 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); |
104 | html("</td>"); | 108 | html("</td>"); |
105 | } | 109 | } |
106 | html("</tr>\n"); | 110 | html("</tr>\n"); |
107 | } | 111 | } |
108 | html("</table>"); | 112 | html("</table>"); |
109 | cgit_print_docend(); | 113 | cgit_print_docend(); |
110 | } | 114 | } |