author | Lars Hjemli <hjemli@gmail.com> | 2007-10-28 14:40:47 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-28 14:41:58 (UTC) |
commit | fc5880fab8b9afc589aaadd1299c34a6ef2a3c2d (patch) (unidiff) | |
tree | a429f34b01fc1ce9a90d46b81915db5fa124f83b | |
parent | cbcdbcf2bff23113fe81df8f11fe7843b8ed637e (diff) | |
download | cgit-fc5880fab8b9afc589aaadd1299c34a6ef2a3c2d.zip cgit-fc5880fab8b9afc589aaadd1299c34a6ef2a3c2d.tar.gz cgit-fc5880fab8b9afc589aaadd1299c34a6ef2a3c2d.tar.bz2 |
Teach cgit_object_link() about tag objects
This makes random tag links more helpfull, e.g. when a branch head references
a tag object, link to the tag page.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index 45105dc..1418010 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,444 +1,447 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
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 | 10 | ||
11 | const char cgit_doctype[] = | 11 | const char cgit_doctype[] = |
12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
14 | 14 | ||
15 | static char *http_date(time_t t) | 15 | static char *http_date(time_t t) |
16 | { | 16 | { |
17 | static char day[][4] = | 17 | static char day[][4] = |
18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
19 | static char month[][4] = | 19 | static char month[][4] = |
20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
22 | struct tm *tm = gmtime(&t); | 22 | struct tm *tm = gmtime(&t); |
23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
25 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 25 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
26 | } | 26 | } |
27 | 27 | ||
28 | static long ttl_seconds(long ttl) | 28 | static long ttl_seconds(long ttl) |
29 | { | 29 | { |
30 | if (ttl<0) | 30 | if (ttl<0) |
31 | return 60 * 60 * 24 * 365; | 31 | return 60 * 60 * 24 * 365; |
32 | else | 32 | else |
33 | return ttl * 60; | 33 | return ttl * 60; |
34 | } | 34 | } |
35 | 35 | ||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_fileurl(const char *reponame, const char *pagename, | 60 | char *cgit_fileurl(const char *reponame, const char *pagename, |
61 | const char *filename, const char *query) | 61 | const char *filename, const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, |
66 | pagename, filename?filename:"", query); | 66 | pagename, filename?filename:"", query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_pageurl(const char *reponame, const char *pagename, | 78 | char *cgit_pageurl(const char *reponame, const char *pagename, |
79 | const char *query) | 79 | const char *query) |
80 | { | 80 | { |
81 | return cgit_fileurl(reponame,pagename,0,query); | 81 | return cgit_fileurl(reponame,pagename,0,query); |
82 | } | 82 | } |
83 | 83 | ||
84 | const char *cgit_repobasename(const char *reponame) | 84 | const char *cgit_repobasename(const char *reponame) |
85 | { | 85 | { |
86 | /* I assume we don't need to store more than one repo basename */ | 86 | /* I assume we don't need to store more than one repo basename */ |
87 | static char rvbuf[1024]; | 87 | static char rvbuf[1024]; |
88 | int p; | 88 | int p; |
89 | const char *rv; | 89 | const char *rv; |
90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
91 | if(rvbuf[sizeof(rvbuf)-1]) | 91 | if(rvbuf[sizeof(rvbuf)-1]) |
92 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 92 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
93 | p = strlen(rvbuf)-1; | 93 | p = strlen(rvbuf)-1; |
94 | /* strip trailing slashes */ | 94 | /* strip trailing slashes */ |
95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
96 | /* strip trailing .git */ | 96 | /* strip trailing .git */ |
97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
98 | p -= 3; rvbuf[p--] = 0; | 98 | p -= 3; rvbuf[p--] = 0; |
99 | } | 99 | } |
100 | /* strip more trailing slashes if any */ | 100 | /* strip more trailing slashes if any */ |
101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
102 | /* find last slash in the remaining string */ | 102 | /* find last slash in the remaining string */ |
103 | rv = strrchr(rvbuf,'/'); | 103 | rv = strrchr(rvbuf,'/'); |
104 | if(rv) | 104 | if(rv) |
105 | return ++rv; | 105 | return ++rv; |
106 | return rvbuf; | 106 | return rvbuf; |
107 | } | 107 | } |
108 | 108 | ||
109 | char *cgit_currurl() | 109 | char *cgit_currurl() |
110 | { | 110 | { |
111 | if (!cgit_virtual_root) | 111 | if (!cgit_virtual_root) |
112 | return cgit_script_name; | 112 | return cgit_script_name; |
113 | else if (cgit_query_page) | 113 | else if (cgit_query_page) |
114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
115 | else if (cgit_query_repo) | 115 | else if (cgit_query_repo) |
116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
117 | else | 117 | else |
118 | return fmt("%s/", cgit_virtual_root); | 118 | return fmt("%s/", cgit_virtual_root); |
119 | } | 119 | } |
120 | 120 | ||
121 | static char *repolink(char *title, char *class, char *page, char *head, | 121 | static char *repolink(char *title, char *class, char *page, char *head, |
122 | char *path) | 122 | char *path) |
123 | { | 123 | { |
124 | char *delim = "?"; | 124 | char *delim = "?"; |
125 | 125 | ||
126 | html("<a"); | 126 | html("<a"); |
127 | if (title) { | 127 | if (title) { |
128 | html(" title='"); | 128 | html(" title='"); |
129 | html_attr(title); | 129 | html_attr(title); |
130 | html("'"); | 130 | html("'"); |
131 | } | 131 | } |
132 | if (class) { | 132 | if (class) { |
133 | html(" class='"); | 133 | html(" class='"); |
134 | html_attr(class); | 134 | html_attr(class); |
135 | html("'"); | 135 | html("'"); |
136 | } | 136 | } |
137 | html(" href='"); | 137 | html(" href='"); |
138 | if (cgit_virtual_root) { | 138 | if (cgit_virtual_root) { |
139 | html_attr(cgit_virtual_root); | 139 | html_attr(cgit_virtual_root); |
140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
141 | html("/"); | 141 | html("/"); |
142 | html_attr(cgit_repo->url); | 142 | html_attr(cgit_repo->url); |
143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
144 | html("/"); | 144 | html("/"); |
145 | if (page) { | 145 | if (page) { |
146 | html(page); | 146 | html(page); |
147 | html("/"); | 147 | html("/"); |
148 | if (path) | 148 | if (path) |
149 | html_attr(path); | 149 | html_attr(path); |
150 | } | 150 | } |
151 | } else { | 151 | } else { |
152 | html(cgit_script_name); | 152 | html(cgit_script_name); |
153 | html("?url="); | 153 | html("?url="); |
154 | html_attr(cgit_repo->url); | 154 | html_attr(cgit_repo->url); |
155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
156 | html("/"); | 156 | html("/"); |
157 | if (page) { | 157 | if (page) { |
158 | html(page); | 158 | html(page); |
159 | html("/"); | 159 | html("/"); |
160 | if (path) | 160 | if (path) |
161 | html_attr(path); | 161 | html_attr(path); |
162 | } | 162 | } |
163 | delim = "&"; | 163 | delim = "&"; |
164 | } | 164 | } |
165 | if (head && strcmp(head, cgit_repo->defbranch)) { | 165 | if (head && strcmp(head, cgit_repo->defbranch)) { |
166 | html(delim); | 166 | html(delim); |
167 | html("h="); | 167 | html("h="); |
168 | html_attr(head); | 168 | html_attr(head); |
169 | delim = "&"; | 169 | delim = "&"; |
170 | } | 170 | } |
171 | return fmt("%s", delim); | 171 | return fmt("%s", delim); |
172 | } | 172 | } |
173 | 173 | ||
174 | static void reporevlink(char *page, char *name, char *title, char *class, | 174 | static void reporevlink(char *page, char *name, char *title, char *class, |
175 | char *head, char *rev, char *path) | 175 | char *head, char *rev, char *path) |
176 | { | 176 | { |
177 | char *delim; | 177 | char *delim; |
178 | 178 | ||
179 | delim = repolink(title, class, page, head, path); | 179 | delim = repolink(title, class, page, head, path); |
180 | if (rev && strcmp(rev, cgit_query_head)) { | 180 | if (rev && strcmp(rev, cgit_query_head)) { |
181 | html(delim); | 181 | html(delim); |
182 | html("id="); | 182 | html("id="); |
183 | html_attr(rev); | 183 | html_attr(rev); |
184 | } | 184 | } |
185 | html("'>"); | 185 | html("'>"); |
186 | html_txt(name); | 186 | html_txt(name); |
187 | html("</a>"); | 187 | html("</a>"); |
188 | } | 188 | } |
189 | 189 | ||
190 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 190 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
191 | char *rev, char *path) | 191 | char *rev, char *path) |
192 | { | 192 | { |
193 | reporevlink("tree", name, title, class, head, rev, path); | 193 | reporevlink("tree", name, title, class, head, rev, path); |
194 | } | 194 | } |
195 | 195 | ||
196 | void cgit_log_link(char *name, char *title, char *class, char *head, | 196 | void cgit_log_link(char *name, char *title, char *class, char *head, |
197 | char *rev, char *path, int ofs) | 197 | char *rev, char *path, int ofs) |
198 | { | 198 | { |
199 | char *delim; | 199 | char *delim; |
200 | 200 | ||
201 | delim = repolink(title, class, "log", head, path); | 201 | delim = repolink(title, class, "log", head, path); |
202 | if (rev && strcmp(rev, cgit_query_head)) { | 202 | if (rev && strcmp(rev, cgit_query_head)) { |
203 | html(delim); | 203 | html(delim); |
204 | html("id="); | 204 | html("id="); |
205 | html_attr(rev); | 205 | html_attr(rev); |
206 | delim = "&"; | 206 | delim = "&"; |
207 | } | 207 | } |
208 | if (ofs > 0) { | 208 | if (ofs > 0) { |
209 | html(delim); | 209 | html(delim); |
210 | html("ofs="); | 210 | html("ofs="); |
211 | htmlf("%d", ofs); | 211 | htmlf("%d", ofs); |
212 | } | 212 | } |
213 | html("'>"); | 213 | html("'>"); |
214 | html_txt(name); | 214 | html_txt(name); |
215 | html("</a>"); | 215 | html("</a>"); |
216 | } | 216 | } |
217 | 217 | ||
218 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 218 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
219 | char *rev) | 219 | char *rev) |
220 | { | 220 | { |
221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
222 | name[cgit_max_msg_len] = '\0'; | 222 | name[cgit_max_msg_len] = '\0'; |
223 | name[cgit_max_msg_len - 1] = '.'; | 223 | name[cgit_max_msg_len - 1] = '.'; |
224 | name[cgit_max_msg_len - 2] = '.'; | 224 | name[cgit_max_msg_len - 2] = '.'; |
225 | name[cgit_max_msg_len - 3] = '.'; | 225 | name[cgit_max_msg_len - 3] = '.'; |
226 | } | 226 | } |
227 | reporevlink("commit", name, title, class, head, rev, NULL); | 227 | reporevlink("commit", name, title, class, head, rev, NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 230 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
231 | char *rev, char *path) | 231 | char *rev, char *path) |
232 | { | 232 | { |
233 | reporevlink("refs", name, title, class, head, rev, path); | 233 | reporevlink("refs", name, title, class, head, rev, path); |
234 | } | 234 | } |
235 | 235 | ||
236 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 236 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
237 | char *rev, char *archivename) | 237 | char *rev, char *archivename) |
238 | { | 238 | { |
239 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 239 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
240 | } | 240 | } |
241 | 241 | ||
242 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 242 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
243 | char *new_rev, char *old_rev, char *path) | 243 | char *new_rev, char *old_rev, char *path) |
244 | { | 244 | { |
245 | char *delim; | 245 | char *delim; |
246 | 246 | ||
247 | delim = repolink(title, class, "diff", head, path); | 247 | delim = repolink(title, class, "diff", head, path); |
248 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 248 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
249 | html(delim); | 249 | html(delim); |
250 | html("id="); | 250 | html("id="); |
251 | html_attr(new_rev); | 251 | html_attr(new_rev); |
252 | delim = "&"; | 252 | delim = "&"; |
253 | } | 253 | } |
254 | if (old_rev) { | 254 | if (old_rev) { |
255 | html(delim); | 255 | html(delim); |
256 | html("id2="); | 256 | html("id2="); |
257 | html_attr(old_rev); | 257 | html_attr(old_rev); |
258 | } | 258 | } |
259 | html("'>"); | 259 | html("'>"); |
260 | html_txt(name); | 260 | html_txt(name); |
261 | html("</a>"); | 261 | html("</a>"); |
262 | } | 262 | } |
263 | 263 | ||
264 | void cgit_object_link(struct object *obj) | 264 | void cgit_object_link(struct object *obj) |
265 | { | 265 | { |
266 | char *page, *arg, *url; | 266 | char *page, *arg, *url; |
267 | 267 | ||
268 | if (obj->type == OBJ_COMMIT) { | 268 | if (obj->type == OBJ_COMMIT) { |
269 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 269 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
270 | cgit_query_head, sha1_to_hex(obj->sha1)); | 270 | cgit_query_head, sha1_to_hex(obj->sha1)); |
271 | return; | 271 | return; |
272 | } else if (obj->type == OBJ_TREE) { | 272 | } else if (obj->type == OBJ_TREE) { |
273 | page = "tree"; | 273 | page = "tree"; |
274 | arg = "id"; | 274 | arg = "id"; |
275 | } else if (obj->type == OBJ_TAG) { | ||
276 | page = "tag"; | ||
277 | arg = "id"; | ||
275 | } else { | 278 | } else { |
276 | page = "blob"; | 279 | page = "blob"; |
277 | arg = "id"; | 280 | arg = "id"; |
278 | } | 281 | } |
279 | 282 | ||
280 | url = cgit_pageurl(cgit_query_repo, page, | 283 | url = cgit_pageurl(cgit_query_repo, page, |
281 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 284 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
282 | html_link_open(url, NULL, NULL); | 285 | html_link_open(url, NULL, NULL); |
283 | htmlf("%s %s", typename(obj->type), | 286 | htmlf("%s %s", typename(obj->type), |
284 | sha1_to_hex(obj->sha1)); | 287 | sha1_to_hex(obj->sha1)); |
285 | html_link_close(); | 288 | html_link_close(); |
286 | } | 289 | } |
287 | 290 | ||
288 | void cgit_print_date(time_t secs, char *format) | 291 | void cgit_print_date(time_t secs, char *format) |
289 | { | 292 | { |
290 | char buf[64]; | 293 | char buf[64]; |
291 | struct tm *time; | 294 | struct tm *time; |
292 | 295 | ||
293 | time = gmtime(&secs); | 296 | time = gmtime(&secs); |
294 | strftime(buf, sizeof(buf)-1, format, time); | 297 | strftime(buf, sizeof(buf)-1, format, time); |
295 | html_txt(buf); | 298 | html_txt(buf); |
296 | } | 299 | } |
297 | 300 | ||
298 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 301 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
299 | { | 302 | { |
300 | time_t now, secs; | 303 | time_t now, secs; |
301 | 304 | ||
302 | time(&now); | 305 | time(&now); |
303 | secs = now - t; | 306 | secs = now - t; |
304 | 307 | ||
305 | if (secs > max_relative && max_relative >= 0) { | 308 | if (secs > max_relative && max_relative >= 0) { |
306 | cgit_print_date(t, format); | 309 | cgit_print_date(t, format); |
307 | return; | 310 | return; |
308 | } | 311 | } |
309 | 312 | ||
310 | if (secs < TM_HOUR * 2) { | 313 | if (secs < TM_HOUR * 2) { |
311 | htmlf("<span class='age-mins'>%.0f min.</span>", | 314 | htmlf("<span class='age-mins'>%.0f min.</span>", |
312 | secs * 1.0 / TM_MIN); | 315 | secs * 1.0 / TM_MIN); |
313 | return; | 316 | return; |
314 | } | 317 | } |
315 | if (secs < TM_DAY * 2) { | 318 | if (secs < TM_DAY * 2) { |
316 | htmlf("<span class='age-hours'>%.0f hours</span>", | 319 | htmlf("<span class='age-hours'>%.0f hours</span>", |
317 | secs * 1.0 / TM_HOUR); | 320 | secs * 1.0 / TM_HOUR); |
318 | return; | 321 | return; |
319 | } | 322 | } |
320 | if (secs < TM_WEEK * 2) { | 323 | if (secs < TM_WEEK * 2) { |
321 | htmlf("<span class='age-days'>%.0f days</span>", | 324 | htmlf("<span class='age-days'>%.0f days</span>", |
322 | secs * 1.0 / TM_DAY); | 325 | secs * 1.0 / TM_DAY); |
323 | return; | 326 | return; |
324 | } | 327 | } |
325 | if (secs < TM_MONTH * 2) { | 328 | if (secs < TM_MONTH * 2) { |
326 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 329 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
327 | secs * 1.0 / TM_WEEK); | 330 | secs * 1.0 / TM_WEEK); |
328 | return; | 331 | return; |
329 | } | 332 | } |
330 | if (secs < TM_YEAR * 2) { | 333 | if (secs < TM_YEAR * 2) { |
331 | htmlf("<span class='age-months'>%.0f months</span>", | 334 | htmlf("<span class='age-months'>%.0f months</span>", |
332 | secs * 1.0 / TM_MONTH); | 335 | secs * 1.0 / TM_MONTH); |
333 | return; | 336 | return; |
334 | } | 337 | } |
335 | htmlf("<span class='age-years'>%.0f years</span>", | 338 | htmlf("<span class='age-years'>%.0f years</span>", |
336 | secs * 1.0 / TM_YEAR); | 339 | secs * 1.0 / TM_YEAR); |
337 | } | 340 | } |
338 | 341 | ||
339 | void cgit_print_docstart(char *title, struct cacheitem *item) | 342 | void cgit_print_docstart(char *title, struct cacheitem *item) |
340 | { | 343 | { |
341 | html("Content-Type: text/html; charset=utf-8\n"); | 344 | html("Content-Type: text/html; charset=utf-8\n"); |
342 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 345 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
343 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 346 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
344 | ttl_seconds(item->ttl))); | 347 | ttl_seconds(item->ttl))); |
345 | html("\n"); | 348 | html("\n"); |
346 | html(cgit_doctype); | 349 | html(cgit_doctype); |
347 | html("<html>\n"); | 350 | html("<html>\n"); |
348 | html("<head>\n"); | 351 | html("<head>\n"); |
349 | html("<title>"); | 352 | html("<title>"); |
350 | html_txt(title); | 353 | html_txt(title); |
351 | html("</title>\n"); | 354 | html("</title>\n"); |
352 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 355 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
353 | html("<link rel='stylesheet' type='text/css' href='"); | 356 | html("<link rel='stylesheet' type='text/css' href='"); |
354 | html_attr(cgit_css); | 357 | html_attr(cgit_css); |
355 | html("'/>\n"); | 358 | html("'/>\n"); |
356 | html("</head>\n"); | 359 | html("</head>\n"); |
357 | html("<body>\n"); | 360 | html("<body>\n"); |
358 | } | 361 | } |
359 | 362 | ||
360 | void cgit_print_docend() | 363 | void cgit_print_docend() |
361 | { | 364 | { |
362 | html("</td></tr></table>"); | 365 | html("</td></tr></table>"); |
363 | html("</body>\n</html>\n"); | 366 | html("</body>\n</html>\n"); |
364 | } | 367 | } |
365 | 368 | ||
366 | void cgit_print_pageheader(char *title, int show_search) | 369 | void cgit_print_pageheader(char *title, int show_search) |
367 | { | 370 | { |
368 | html("<table id='layout'>"); | 371 | html("<table id='layout'>"); |
369 | html("<tr><td id='header'><a href='"); | 372 | html("<tr><td id='header'><a href='"); |
370 | html_attr(cgit_rooturl()); | 373 | html_attr(cgit_rooturl()); |
371 | html("'>"); | 374 | html("'>"); |
372 | html_txt(cgit_root_title); | 375 | html_txt(cgit_root_title); |
373 | html("</a></td><td id='logo'>"); | 376 | html("</a></td><td id='logo'>"); |
374 | html("<a href='"); | 377 | html("<a href='"); |
375 | html_attr(cgit_logo_link); | 378 | html_attr(cgit_logo_link); |
376 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 379 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
377 | html("</td></tr>"); | 380 | html("</td></tr>"); |
378 | html("<tr><td id='crumb'>"); | 381 | html("<tr><td id='crumb'>"); |
379 | if (cgit_query_repo) { | 382 | if (cgit_query_repo) { |
380 | html_txt(cgit_repo->name); | 383 | html_txt(cgit_repo->name); |
381 | html(" ("); | 384 | html(" ("); |
382 | html_txt(cgit_query_head); | 385 | html_txt(cgit_query_head); |
383 | html(") : "); | 386 | html(") : "); |
384 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, | 387 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, |
385 | NULL, NULL); | 388 | NULL, NULL); |
386 | html(" "); | 389 | html(" "); |
387 | cgit_log_link("log", NULL, NULL, cgit_query_head, | 390 | cgit_log_link("log", NULL, NULL, cgit_query_head, |
388 | cgit_query_sha1, cgit_query_path, 0); | 391 | cgit_query_sha1, cgit_query_path, 0); |
389 | html(" "); | 392 | html(" "); |
390 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, | 393 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, |
391 | cgit_query_sha1, NULL); | 394 | cgit_query_sha1, NULL); |
392 | html(" "); | 395 | html(" "); |
393 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, | 396 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, |
394 | cgit_query_sha1); | 397 | cgit_query_sha1); |
395 | html(" "); | 398 | html(" "); |
396 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, | 399 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, |
397 | cgit_query_sha1, cgit_query_sha2, | 400 | cgit_query_sha1, cgit_query_sha2, |
398 | cgit_query_path); | 401 | cgit_query_path); |
399 | } else { | 402 | } else { |
400 | html_txt("Index of repositories"); | 403 | html_txt("Index of repositories"); |
401 | } | 404 | } |
402 | html("</td>"); | 405 | html("</td>"); |
403 | html("<td id='search'>"); | 406 | html("<td id='search'>"); |
404 | if (show_search) { | 407 | if (show_search) { |
405 | html("<form method='get' action='"); | 408 | html("<form method='get' action='"); |
406 | html_attr(cgit_currurl()); | 409 | html_attr(cgit_currurl()); |
407 | html("'>"); | 410 | html("'>"); |
408 | if (!cgit_virtual_root) { | 411 | if (!cgit_virtual_root) { |
409 | if (cgit_query_repo) | 412 | if (cgit_query_repo) |
410 | html_hidden("r", cgit_query_repo); | 413 | html_hidden("r", cgit_query_repo); |
411 | if (cgit_query_page) | 414 | if (cgit_query_page) |
412 | html_hidden("p", cgit_query_page); | 415 | html_hidden("p", cgit_query_page); |
413 | } | 416 | } |
414 | if (cgit_query_head) | 417 | if (cgit_query_head) |
415 | html_hidden("h", cgit_query_head); | 418 | html_hidden("h", cgit_query_head); |
416 | if (cgit_query_sha1) | 419 | if (cgit_query_sha1) |
417 | html_hidden("id", cgit_query_sha1); | 420 | html_hidden("id", cgit_query_sha1); |
418 | if (cgit_query_sha2) | 421 | if (cgit_query_sha2) |
419 | html_hidden("id2", cgit_query_sha2); | 422 | html_hidden("id2", cgit_query_sha2); |
420 | html("<select name='qt'>"); | 423 | html("<select name='qt'>"); |
421 | html_option("grep", "log msg", cgit_query_grep); | 424 | html_option("grep", "log msg", cgit_query_grep); |
422 | html_option("author", "author", cgit_query_grep); | 425 | html_option("author", "author", cgit_query_grep); |
423 | html_option("committer", "committer", cgit_query_grep); | 426 | html_option("committer", "committer", cgit_query_grep); |
424 | html("</select>"); | 427 | html("</select>"); |
425 | html("<input class='txt' type='text' name='q' value='"); | 428 | html("<input class='txt' type='text' name='q' value='"); |
426 | html_attr(cgit_query_search); | 429 | html_attr(cgit_query_search); |
427 | html("'/><input class='btn' type='submit' value='...'/></form>"); | 430 | html("'/><input class='btn' type='submit' value='...'/></form>"); |
428 | } | 431 | } |
429 | html("</td></tr>"); | 432 | html("</td></tr>"); |
430 | html("<tr><td id='content' colspan='2'>"); | 433 | html("<tr><td id='content' colspan='2'>"); |
431 | } | 434 | } |
432 | 435 | ||
433 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 436 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
434 | struct cacheitem *item) | 437 | struct cacheitem *item) |
435 | { | 438 | { |
436 | htmlf("Content-Type: %s\n", mimetype); | 439 | htmlf("Content-Type: %s\n", mimetype); |
437 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 440 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
438 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 441 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
439 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 442 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
440 | ttl_seconds(item->ttl))); | 443 | ttl_seconds(item->ttl))); |
441 | html("\n"); | 444 | html("\n"); |
442 | } | 445 | } |
443 | 446 | ||
444 | /* vim:set sw=8: */ | 447 | /* vim:set sw=8: */ |