-rw-r--r-- | ui-repolist.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index e5c6c20..8ade91a 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,103 +1,100 @@ | |||
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" | 9 | #include "cgit.h" |
10 | #include <time.h> | 10 | #include <time.h> |
11 | 11 | ||
12 | 12 | ||
13 | time_t read_agefile(char *path) | 13 | time_t read_agefile(char *path) |
14 | { | 14 | { |
15 | FILE *f; | 15 | FILE *f; |
16 | static char buf[64], buf2[64]; | 16 | static char buf[64], buf2[64]; |
17 | 17 | ||
18 | if (!(f = fopen(path, "r"))) | 18 | if (!(f = fopen(path, "r"))) |
19 | return -1; | 19 | return -1; |
20 | fgets(buf, sizeof(buf), f); | 20 | fgets(buf, sizeof(buf), f); |
21 | fclose(f); | 21 | fclose(f); |
22 | if (parse_date(buf, buf2, sizeof(buf2))) | 22 | if (parse_date(buf, buf2, sizeof(buf2))) |
23 | return strtoul(buf2, NULL, 10); | 23 | return strtoul(buf2, NULL, 10); |
24 | else | 24 | else |
25 | return 0; | 25 | return 0; |
26 | } | 26 | } |
27 | 27 | ||
28 | static void print_modtime(struct repoinfo *repo) | 28 | static void print_modtime(struct repoinfo *repo) |
29 | { | 29 | { |
30 | char *path; | 30 | char *path; |
31 | struct stat s; | 31 | struct stat s; |
32 | 32 | ||
33 | path = fmt("%s/%s", repo->path, cgit_agefile); | 33 | path = fmt("%s/%s", repo->path, cgit_agefile); |
34 | if (stat(path, &s) == 0) { | 34 | if (stat(path, &s) == 0) { |
35 | cgit_print_age(read_agefile(path), -1, NULL); | 35 | cgit_print_age(read_agefile(path), -1, NULL); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
40 | if (stat(path, &s) != 0) | 40 | if (stat(path, &s) != 0) |
41 | return; | 41 | return; |
42 | cgit_print_age(s.st_mtime, -1, NULL); | 42 | cgit_print_age(s.st_mtime, -1, NULL); |
43 | } | 43 | } |
44 | 44 | ||
45 | void cgit_print_repolist(struct cacheitem *item) | 45 | void cgit_print_repolist(struct cacheitem *item) |
46 | { | 46 | { |
47 | struct repoinfo *repo; | ||
48 | int i; | 47 | int i; |
49 | char *last_group = NULL; | 48 | char *last_group = NULL; |
50 | 49 | ||
51 | cgit_print_docstart(cgit_root_title, item); | 50 | cgit_print_docstart(cgit_root_title, item); |
52 | cgit_print_pageheader(cgit_root_title, 0); | 51 | cgit_print_pageheader(cgit_root_title, 0); |
53 | 52 | ||
54 | html("<table class='list nowrap'>"); | 53 | html("<table class='list nowrap'>"); |
55 | if (cgit_index_header) { | 54 | if (cgit_index_header) { |
56 | html("<tr class='nohover'><td colspan='5' class='include-block'>"); | 55 | html("<tr class='nohover'><td colspan='5' class='include-block'>"); |
57 | html_include(cgit_index_header); | 56 | html_include(cgit_index_header); |
58 | html("</td></tr>"); | 57 | html("</td></tr>"); |
59 | } | 58 | } |
60 | html("<tr class='nohover'>" | 59 | html("<tr class='nohover'>" |
61 | "<th class='left'>Name</th>" | 60 | "<th class='left'>Name</th>" |
62 | "<th class='left'>Description</th>" | 61 | "<th class='left'>Description</th>" |
63 | "<th class='left'>Owner</th>" | 62 | "<th class='left'>Owner</th>" |
64 | "<th class='left'>Idle</th>" | 63 | "<th class='left'>Idle</th>" |
65 | "<th>Links</th></tr>\n"); | 64 | "<th>Links</th></tr>\n"); |
66 | 65 | ||
67 | for (i=0; i<cgit_repolist.count; i++) { | 66 | for (i=0; i<cgit_repolist.count; i++) { |
68 | repo = &cgit_repolist.repos[i]; | 67 | cgit_repo = &cgit_repolist.repos[i]; |
69 | if ((last_group == NULL && repo->group != NULL) || | 68 | if ((last_group == NULL && cgit_repo->group != NULL) || |
70 | (last_group != NULL && repo->group == NULL) || | 69 | (last_group != NULL && cgit_repo->group == NULL) || |
71 | (last_group != NULL && repo->group!= NULL && | 70 | (last_group != NULL && cgit_repo->group != NULL && |
72 | strcmp(repo->group, last_group))) { | 71 | strcmp(cgit_repo->group, last_group))) { |
73 | html("<tr class='nohover'><td colspan='4' class='repogroup'>"); | 72 | html("<tr class='nohover'><td colspan='4' class='repogroup'>"); |
74 | html_txt(repo->group); | 73 | html_txt(cgit_repo->group); |
75 | html("</td></tr>"); | 74 | html("</td></tr>"); |
76 | last_group = repo->group; | 75 | last_group = cgit_repo->group; |
77 | } | 76 | } |
78 | htmlf("<tr><td class='%s'>", | 77 | htmlf("<tr><td class='%s'>", |
79 | repo->group ? "sublevel-repo" : "toplevel-repo"); | 78 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); |
80 | html_link_open(cgit_repourl(repo->url), repo->desc, NULL); | 79 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); |
81 | html_txt(repo->name); | 80 | html_txt(cgit_repo->name); |
82 | html_link_close(); | 81 | html_link_close(); |
83 | html("</td><td>"); | 82 | html("</td><td>"); |
84 | html_ntxt(cgit_max_repodesc_len, repo->desc); | 83 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); |
85 | html("</td><td>"); | 84 | html("</td><td>"); |
86 | html_txt(repo->owner); | 85 | html_txt(cgit_repo->owner); |
87 | html("</td><td>"); | 86 | html("</td><td>"); |
88 | print_modtime(repo); | 87 | print_modtime(cgit_repo); |
89 | html("</td><td>"); | 88 | html("</td><td>"); |
90 | html_link_open(cgit_repourl(repo->url), | 89 | html_link_open(cgit_repourl(cgit_repo->url), |
91 | "Summary", "button"); | 90 | "Summary", "button"); |
92 | html("S</a>"); | 91 | html("S</a>"); |
93 | html_link_open(cgit_pageurl(repo->name, "log", NULL), | 92 | html_link_open(cgit_pageurl(cgit_repo->name, "log", NULL), |
94 | "Log", "button"); | 93 | "Log", "button"); |
95 | html("L</a>"); | 94 | html("L</a>"); |
96 | html_link_open(cgit_pageurl(repo->name, "tree", NULL), | 95 | cgit_tree_link("F", "Files", "button", NULL, NULL, NULL); |
97 | "Files", "button"); | ||
98 | html("F</a>"); | ||
99 | html("</td></tr>\n"); | 96 | html("</td></tr>\n"); |
100 | } | 97 | } |
101 | html("</table>"); | 98 | html("</table>"); |
102 | cgit_print_docend(); | 99 | cgit_print_docend(); |
103 | } | 100 | } |