-rw-r--r-- | ui-shared.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index de77bbf..749ea35 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,420 +1,431 @@ | |||
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 | #include "cmd.h" | 10 | #include "cmd.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | 12 | ||
13 | const char cgit_doctype[] = | 13 | const char cgit_doctype[] = |
14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
16 | 16 | ||
17 | static char *http_date(time_t t) | 17 | static char *http_date(time_t t) |
18 | { | 18 | { |
19 | static char day[][4] = | 19 | static char day[][4] = |
20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
21 | static char month[][4] = | 21 | static char month[][4] = |
22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
23 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 23 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
24 | struct tm *tm = gmtime(&t); | 24 | struct tm *tm = gmtime(&t); |
25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
27 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
28 | } | 28 | } |
29 | 29 | ||
30 | void cgit_print_error(char *msg) | 30 | void cgit_print_error(char *msg) |
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
34 | html("</div>\n"); | 34 | html("</div>\n"); |
35 | } | 35 | } |
36 | 36 | ||
37 | char *cgit_httpscheme() | ||
38 | { | ||
39 | char *https; | ||
40 | |||
41 | https = getenv("HTTPS"); | ||
42 | if (https != NULL && strcmp(https, "on") == 0) | ||
43 | return "https://"; | ||
44 | else | ||
45 | return "http://"; | ||
46 | } | ||
47 | |||
37 | char *cgit_hosturl() | 48 | char *cgit_hosturl() |
38 | { | 49 | { |
39 | char *host, *port; | 50 | char *host, *port; |
40 | 51 | ||
41 | host = getenv("HTTP_HOST"); | 52 | host = getenv("HTTP_HOST"); |
42 | if (host) { | 53 | if (host) { |
43 | host = xstrdup(host); | 54 | host = xstrdup(host); |
44 | } else { | 55 | } else { |
45 | host = getenv("SERVER_NAME"); | 56 | host = getenv("SERVER_NAME"); |
46 | if (!host) | 57 | if (!host) |
47 | return NULL; | 58 | return NULL; |
48 | port = getenv("SERVER_PORT"); | 59 | port = getenv("SERVER_PORT"); |
49 | if (port && atoi(port) != 80) | 60 | if (port && atoi(port) != 80) |
50 | host = xstrdup(fmt("%s:%d", host, atoi(port))); | 61 | host = xstrdup(fmt("%s:%d", host, atoi(port))); |
51 | else | 62 | else |
52 | host = xstrdup(host); | 63 | host = xstrdup(host); |
53 | } | 64 | } |
54 | return host; | 65 | return host; |
55 | } | 66 | } |
56 | 67 | ||
57 | char *cgit_rooturl() | 68 | char *cgit_rooturl() |
58 | { | 69 | { |
59 | if (ctx.cfg.virtual_root) | 70 | if (ctx.cfg.virtual_root) |
60 | return fmt("%s/", ctx.cfg.virtual_root); | 71 | return fmt("%s/", ctx.cfg.virtual_root); |
61 | else | 72 | else |
62 | return ctx.cfg.script_name; | 73 | return ctx.cfg.script_name; |
63 | } | 74 | } |
64 | 75 | ||
65 | char *cgit_repourl(const char *reponame) | 76 | char *cgit_repourl(const char *reponame) |
66 | { | 77 | { |
67 | if (ctx.cfg.virtual_root) { | 78 | if (ctx.cfg.virtual_root) { |
68 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 79 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
69 | } else { | 80 | } else { |
70 | return fmt("?r=%s", reponame); | 81 | return fmt("?r=%s", reponame); |
71 | } | 82 | } |
72 | } | 83 | } |
73 | 84 | ||
74 | char *cgit_fileurl(const char *reponame, const char *pagename, | 85 | char *cgit_fileurl(const char *reponame, const char *pagename, |
75 | const char *filename, const char *query) | 86 | const char *filename, const char *query) |
76 | { | 87 | { |
77 | char *tmp; | 88 | char *tmp; |
78 | char *delim; | 89 | char *delim; |
79 | 90 | ||
80 | if (ctx.cfg.virtual_root) { | 91 | if (ctx.cfg.virtual_root) { |
81 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, | 92 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
82 | pagename, (filename ? filename:"")); | 93 | pagename, (filename ? filename:"")); |
83 | delim = "?"; | 94 | delim = "?"; |
84 | } else { | 95 | } else { |
85 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, | 96 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, |
86 | (filename ? filename : "")); | 97 | (filename ? filename : "")); |
87 | delim = "&"; | 98 | delim = "&"; |
88 | } | 99 | } |
89 | if (query) | 100 | if (query) |
90 | tmp = fmt("%s%s%s", tmp, delim, query); | 101 | tmp = fmt("%s%s%s", tmp, delim, query); |
91 | return tmp; | 102 | return tmp; |
92 | } | 103 | } |
93 | 104 | ||
94 | char *cgit_pageurl(const char *reponame, const char *pagename, | 105 | char *cgit_pageurl(const char *reponame, const char *pagename, |
95 | const char *query) | 106 | const char *query) |
96 | { | 107 | { |
97 | return cgit_fileurl(reponame,pagename,0,query); | 108 | return cgit_fileurl(reponame,pagename,0,query); |
98 | } | 109 | } |
99 | 110 | ||
100 | const char *cgit_repobasename(const char *reponame) | 111 | const char *cgit_repobasename(const char *reponame) |
101 | { | 112 | { |
102 | /* I assume we don't need to store more than one repo basename */ | 113 | /* I assume we don't need to store more than one repo basename */ |
103 | static char rvbuf[1024]; | 114 | static char rvbuf[1024]; |
104 | int p; | 115 | int p; |
105 | const char *rv; | 116 | const char *rv; |
106 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 117 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
107 | if(rvbuf[sizeof(rvbuf)-1]) | 118 | if(rvbuf[sizeof(rvbuf)-1]) |
108 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 119 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
109 | p = strlen(rvbuf)-1; | 120 | p = strlen(rvbuf)-1; |
110 | /* strip trailing slashes */ | 121 | /* strip trailing slashes */ |
111 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 122 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
112 | /* strip trailing .git */ | 123 | /* strip trailing .git */ |
113 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 124 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
114 | p -= 3; rvbuf[p--] = 0; | 125 | p -= 3; rvbuf[p--] = 0; |
115 | } | 126 | } |
116 | /* strip more trailing slashes if any */ | 127 | /* strip more trailing slashes if any */ |
117 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 128 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
118 | /* find last slash in the remaining string */ | 129 | /* find last slash in the remaining string */ |
119 | rv = strrchr(rvbuf,'/'); | 130 | rv = strrchr(rvbuf,'/'); |
120 | if(rv) | 131 | if(rv) |
121 | return ++rv; | 132 | return ++rv; |
122 | return rvbuf; | 133 | return rvbuf; |
123 | } | 134 | } |
124 | 135 | ||
125 | char *cgit_currurl() | 136 | char *cgit_currurl() |
126 | { | 137 | { |
127 | if (!ctx.cfg.virtual_root) | 138 | if (!ctx.cfg.virtual_root) |
128 | return ctx.cfg.script_name; | 139 | return ctx.cfg.script_name; |
129 | else if (ctx.qry.page) | 140 | else if (ctx.qry.page) |
130 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 141 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
131 | else if (ctx.qry.repo) | 142 | else if (ctx.qry.repo) |
132 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 143 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
133 | else | 144 | else |
134 | return fmt("%s/", ctx.cfg.virtual_root); | 145 | return fmt("%s/", ctx.cfg.virtual_root); |
135 | } | 146 | } |
136 | 147 | ||
137 | static void site_url(char *page, char *search, int ofs) | 148 | static void site_url(char *page, char *search, int ofs) |
138 | { | 149 | { |
139 | char *delim = "?"; | 150 | char *delim = "?"; |
140 | 151 | ||
141 | if (ctx.cfg.virtual_root) { | 152 | if (ctx.cfg.virtual_root) { |
142 | html_attr(ctx.cfg.virtual_root); | 153 | html_attr(ctx.cfg.virtual_root); |
143 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 154 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
144 | html("/"); | 155 | html("/"); |
145 | } else | 156 | } else |
146 | html(ctx.cfg.script_name); | 157 | html(ctx.cfg.script_name); |
147 | 158 | ||
148 | if (page) { | 159 | if (page) { |
149 | htmlf("?p=%s", page); | 160 | htmlf("?p=%s", page); |
150 | delim = "&"; | 161 | delim = "&"; |
151 | } | 162 | } |
152 | if (search) { | 163 | if (search) { |
153 | html(delim); | 164 | html(delim); |
154 | html("q="); | 165 | html("q="); |
155 | html_attr(search); | 166 | html_attr(search); |
156 | delim = "&"; | 167 | delim = "&"; |
157 | } | 168 | } |
158 | if (ofs) { | 169 | if (ofs) { |
159 | html(delim); | 170 | html(delim); |
160 | htmlf("ofs=%d", ofs); | 171 | htmlf("ofs=%d", ofs); |
161 | } | 172 | } |
162 | } | 173 | } |
163 | 174 | ||
164 | static void site_link(char *page, char *name, char *title, char *class, | 175 | static void site_link(char *page, char *name, char *title, char *class, |
165 | char *search, int ofs) | 176 | char *search, int ofs) |
166 | { | 177 | { |
167 | html("<a"); | 178 | html("<a"); |
168 | if (title) { | 179 | if (title) { |
169 | html(" title='"); | 180 | html(" title='"); |
170 | html_attr(title); | 181 | html_attr(title); |
171 | html("'"); | 182 | html("'"); |
172 | } | 183 | } |
173 | if (class) { | 184 | if (class) { |
174 | html(" class='"); | 185 | html(" class='"); |
175 | html_attr(class); | 186 | html_attr(class); |
176 | html("'"); | 187 | html("'"); |
177 | } | 188 | } |
178 | html(" href='"); | 189 | html(" href='"); |
179 | site_url(page, search, ofs); | 190 | site_url(page, search, ofs); |
180 | html("'>"); | 191 | html("'>"); |
181 | html_txt(name); | 192 | html_txt(name); |
182 | html("</a>"); | 193 | html("</a>"); |
183 | } | 194 | } |
184 | 195 | ||
185 | void cgit_index_link(char *name, char *title, char *class, char *pattern, | 196 | void cgit_index_link(char *name, char *title, char *class, char *pattern, |
186 | int ofs) | 197 | int ofs) |
187 | { | 198 | { |
188 | site_link(NULL, name, title, class, pattern, ofs); | 199 | site_link(NULL, name, title, class, pattern, ofs); |
189 | } | 200 | } |
190 | 201 | ||
191 | static char *repolink(char *title, char *class, char *page, char *head, | 202 | static char *repolink(char *title, char *class, char *page, char *head, |
192 | char *path) | 203 | char *path) |
193 | { | 204 | { |
194 | char *delim = "?"; | 205 | char *delim = "?"; |
195 | 206 | ||
196 | html("<a"); | 207 | html("<a"); |
197 | if (title) { | 208 | if (title) { |
198 | html(" title='"); | 209 | html(" title='"); |
199 | html_attr(title); | 210 | html_attr(title); |
200 | html("'"); | 211 | html("'"); |
201 | } | 212 | } |
202 | if (class) { | 213 | if (class) { |
203 | html(" class='"); | 214 | html(" class='"); |
204 | html_attr(class); | 215 | html_attr(class); |
205 | html("'"); | 216 | html("'"); |
206 | } | 217 | } |
207 | html(" href='"); | 218 | html(" href='"); |
208 | if (ctx.cfg.virtual_root) { | 219 | if (ctx.cfg.virtual_root) { |
209 | html_url_path(ctx.cfg.virtual_root); | 220 | html_url_path(ctx.cfg.virtual_root); |
210 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 221 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
211 | html("/"); | 222 | html("/"); |
212 | html_url_path(ctx.repo->url); | 223 | html_url_path(ctx.repo->url); |
213 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 224 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
214 | html("/"); | 225 | html("/"); |
215 | if (page) { | 226 | if (page) { |
216 | html_url_path(page); | 227 | html_url_path(page); |
217 | html("/"); | 228 | html("/"); |
218 | if (path) | 229 | if (path) |
219 | html_url_path(path); | 230 | html_url_path(path); |
220 | } | 231 | } |
221 | } else { | 232 | } else { |
222 | html(ctx.cfg.script_name); | 233 | html(ctx.cfg.script_name); |
223 | html("?url="); | 234 | html("?url="); |
224 | html_url_arg(ctx.repo->url); | 235 | html_url_arg(ctx.repo->url); |
225 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 236 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
226 | html("/"); | 237 | html("/"); |
227 | if (page) { | 238 | if (page) { |
228 | html_url_arg(page); | 239 | html_url_arg(page); |
229 | html("/"); | 240 | html("/"); |
230 | if (path) | 241 | if (path) |
231 | html_url_arg(path); | 242 | html_url_arg(path); |
232 | } | 243 | } |
233 | delim = "&"; | 244 | delim = "&"; |
234 | } | 245 | } |
235 | if (head && strcmp(head, ctx.repo->defbranch)) { | 246 | if (head && strcmp(head, ctx.repo->defbranch)) { |
236 | html(delim); | 247 | html(delim); |
237 | html("h="); | 248 | html("h="); |
238 | html_url_arg(head); | 249 | html_url_arg(head); |
239 | delim = "&"; | 250 | delim = "&"; |
240 | } | 251 | } |
241 | return fmt("%s", delim); | 252 | return fmt("%s", delim); |
242 | } | 253 | } |
243 | 254 | ||
244 | static void reporevlink(char *page, char *name, char *title, char *class, | 255 | static void reporevlink(char *page, char *name, char *title, char *class, |
245 | char *head, char *rev, char *path) | 256 | char *head, char *rev, char *path) |
246 | { | 257 | { |
247 | char *delim; | 258 | char *delim; |
248 | 259 | ||
249 | delim = repolink(title, class, page, head, path); | 260 | delim = repolink(title, class, page, head, path); |
250 | if (rev && strcmp(rev, ctx.qry.head)) { | 261 | if (rev && strcmp(rev, ctx.qry.head)) { |
251 | html(delim); | 262 | html(delim); |
252 | html("id="); | 263 | html("id="); |
253 | html_url_arg(rev); | 264 | html_url_arg(rev); |
254 | } | 265 | } |
255 | html("'>"); | 266 | html("'>"); |
256 | html_txt(name); | 267 | html_txt(name); |
257 | html("</a>"); | 268 | html("</a>"); |
258 | } | 269 | } |
259 | 270 | ||
260 | void cgit_summary_link(char *name, char *title, char *class, char *head) | 271 | void cgit_summary_link(char *name, char *title, char *class, char *head) |
261 | { | 272 | { |
262 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 273 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
263 | } | 274 | } |
264 | 275 | ||
265 | void cgit_tag_link(char *name, char *title, char *class, char *head, | 276 | void cgit_tag_link(char *name, char *title, char *class, char *head, |
266 | char *rev) | 277 | char *rev) |
267 | { | 278 | { |
268 | reporevlink("tag", name, title, class, head, rev, NULL); | 279 | reporevlink("tag", name, title, class, head, rev, NULL); |
269 | } | 280 | } |
270 | 281 | ||
271 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 282 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
272 | char *rev, char *path) | 283 | char *rev, char *path) |
273 | { | 284 | { |
274 | reporevlink("tree", name, title, class, head, rev, path); | 285 | reporevlink("tree", name, title, class, head, rev, path); |
275 | } | 286 | } |
276 | 287 | ||
277 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 288 | void cgit_plain_link(char *name, char *title, char *class, char *head, |
278 | char *rev, char *path) | 289 | char *rev, char *path) |
279 | { | 290 | { |
280 | reporevlink("plain", name, title, class, head, rev, path); | 291 | reporevlink("plain", name, title, class, head, rev, path); |
281 | } | 292 | } |
282 | 293 | ||
283 | void cgit_log_link(char *name, char *title, char *class, char *head, | 294 | void cgit_log_link(char *name, char *title, char *class, char *head, |
284 | char *rev, char *path, int ofs, char *grep, char *pattern, | 295 | char *rev, char *path, int ofs, char *grep, char *pattern, |
285 | int showmsg) | 296 | int showmsg) |
286 | { | 297 | { |
287 | char *delim; | 298 | char *delim; |
288 | 299 | ||
289 | delim = repolink(title, class, "log", head, path); | 300 | delim = repolink(title, class, "log", head, path); |
290 | if (rev && strcmp(rev, ctx.qry.head)) { | 301 | if (rev && strcmp(rev, ctx.qry.head)) { |
291 | html(delim); | 302 | html(delim); |
292 | html("id="); | 303 | html("id="); |
293 | html_url_arg(rev); | 304 | html_url_arg(rev); |
294 | delim = "&"; | 305 | delim = "&"; |
295 | } | 306 | } |
296 | if (grep && pattern) { | 307 | if (grep && pattern) { |
297 | html(delim); | 308 | html(delim); |
298 | html("qt="); | 309 | html("qt="); |
299 | html_url_arg(grep); | 310 | html_url_arg(grep); |
300 | delim = "&"; | 311 | delim = "&"; |
301 | html(delim); | 312 | html(delim); |
302 | html("q="); | 313 | html("q="); |
303 | html_url_arg(pattern); | 314 | html_url_arg(pattern); |
304 | } | 315 | } |
305 | if (ofs > 0) { | 316 | if (ofs > 0) { |
306 | html(delim); | 317 | html(delim); |
307 | html("ofs="); | 318 | html("ofs="); |
308 | htmlf("%d", ofs); | 319 | htmlf("%d", ofs); |
309 | delim = "&"; | 320 | delim = "&"; |
310 | } | 321 | } |
311 | if (showmsg) { | 322 | if (showmsg) { |
312 | html(delim); | 323 | html(delim); |
313 | html("showmsg=1"); | 324 | html("showmsg=1"); |
314 | } | 325 | } |
315 | html("'>"); | 326 | html("'>"); |
316 | html_txt(name); | 327 | html_txt(name); |
317 | html("</a>"); | 328 | html("</a>"); |
318 | } | 329 | } |
319 | 330 | ||
320 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 331 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
321 | char *rev) | 332 | char *rev) |
322 | { | 333 | { |
323 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 334 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
324 | name[ctx.cfg.max_msg_len] = '\0'; | 335 | name[ctx.cfg.max_msg_len] = '\0'; |
325 | name[ctx.cfg.max_msg_len - 1] = '.'; | 336 | name[ctx.cfg.max_msg_len - 1] = '.'; |
326 | name[ctx.cfg.max_msg_len - 2] = '.'; | 337 | name[ctx.cfg.max_msg_len - 2] = '.'; |
327 | name[ctx.cfg.max_msg_len - 3] = '.'; | 338 | name[ctx.cfg.max_msg_len - 3] = '.'; |
328 | } | 339 | } |
329 | reporevlink("commit", name, title, class, head, rev, NULL); | 340 | reporevlink("commit", name, title, class, head, rev, NULL); |
330 | } | 341 | } |
331 | 342 | ||
332 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 343 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
333 | char *rev, char *path) | 344 | char *rev, char *path) |
334 | { | 345 | { |
335 | reporevlink("refs", name, title, class, head, rev, path); | 346 | reporevlink("refs", name, title, class, head, rev, path); |
336 | } | 347 | } |
337 | 348 | ||
338 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 349 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
339 | char *rev, char *archivename) | 350 | char *rev, char *archivename) |
340 | { | 351 | { |
341 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 352 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
342 | } | 353 | } |
343 | 354 | ||
344 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 355 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
345 | char *new_rev, char *old_rev, char *path) | 356 | char *new_rev, char *old_rev, char *path) |
346 | { | 357 | { |
347 | char *delim; | 358 | char *delim; |
348 | 359 | ||
349 | delim = repolink(title, class, "diff", head, path); | 360 | delim = repolink(title, class, "diff", head, path); |
350 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 361 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
351 | html(delim); | 362 | html(delim); |
352 | html("id="); | 363 | html("id="); |
353 | html_url_arg(new_rev); | 364 | html_url_arg(new_rev); |
354 | delim = "&"; | 365 | delim = "&"; |
355 | } | 366 | } |
356 | if (old_rev) { | 367 | if (old_rev) { |
357 | html(delim); | 368 | html(delim); |
358 | html("id2="); | 369 | html("id2="); |
359 | html_url_arg(old_rev); | 370 | html_url_arg(old_rev); |
360 | } | 371 | } |
361 | html("'>"); | 372 | html("'>"); |
362 | html_txt(name); | 373 | html_txt(name); |
363 | html("</a>"); | 374 | html("</a>"); |
364 | } | 375 | } |
365 | 376 | ||
366 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 377 | void cgit_patch_link(char *name, char *title, char *class, char *head, |
367 | char *rev) | 378 | char *rev) |
368 | { | 379 | { |
369 | reporevlink("patch", name, title, class, head, rev, NULL); | 380 | reporevlink("patch", name, title, class, head, rev, NULL); |
370 | } | 381 | } |
371 | 382 | ||
372 | void cgit_stats_link(char *name, char *title, char *class, char *head, | 383 | void cgit_stats_link(char *name, char *title, char *class, char *head, |
373 | char *path) | 384 | char *path) |
374 | { | 385 | { |
375 | reporevlink("stats", name, title, class, head, NULL, path); | 386 | reporevlink("stats", name, title, class, head, NULL, path); |
376 | } | 387 | } |
377 | 388 | ||
378 | void cgit_object_link(struct object *obj) | 389 | void cgit_object_link(struct object *obj) |
379 | { | 390 | { |
380 | char *page, *shortrev, *fullrev, *name; | 391 | char *page, *shortrev, *fullrev, *name; |
381 | 392 | ||
382 | fullrev = sha1_to_hex(obj->sha1); | 393 | fullrev = sha1_to_hex(obj->sha1); |
383 | shortrev = xstrdup(fullrev); | 394 | shortrev = xstrdup(fullrev); |
384 | shortrev[10] = '\0'; | 395 | shortrev[10] = '\0'; |
385 | if (obj->type == OBJ_COMMIT) { | 396 | if (obj->type == OBJ_COMMIT) { |
386 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 397 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
387 | ctx.qry.head, fullrev); | 398 | ctx.qry.head, fullrev); |
388 | return; | 399 | return; |
389 | } else if (obj->type == OBJ_TREE) | 400 | } else if (obj->type == OBJ_TREE) |
390 | page = "tree"; | 401 | page = "tree"; |
391 | else if (obj->type == OBJ_TAG) | 402 | else if (obj->type == OBJ_TAG) |
392 | page = "tag"; | 403 | page = "tag"; |
393 | else | 404 | else |
394 | page = "blob"; | 405 | page = "blob"; |
395 | name = fmt("%s %s...", typename(obj->type), shortrev); | 406 | name = fmt("%s %s...", typename(obj->type), shortrev); |
396 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 407 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
397 | } | 408 | } |
398 | 409 | ||
399 | void cgit_print_date(time_t secs, char *format, int local_time) | 410 | void cgit_print_date(time_t secs, char *format, int local_time) |
400 | { | 411 | { |
401 | char buf[64]; | 412 | char buf[64]; |
402 | struct tm *time; | 413 | struct tm *time; |
403 | 414 | ||
404 | if (!secs) | 415 | if (!secs) |
405 | return; | 416 | return; |
406 | if(local_time) | 417 | if(local_time) |
407 | time = localtime(&secs); | 418 | time = localtime(&secs); |
408 | else | 419 | else |
409 | time = gmtime(&secs); | 420 | time = gmtime(&secs); |
410 | strftime(buf, sizeof(buf)-1, format, time); | 421 | strftime(buf, sizeof(buf)-1, format, time); |
411 | html_txt(buf); | 422 | html_txt(buf); |
412 | } | 423 | } |
413 | 424 | ||
414 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 425 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
415 | { | 426 | { |
416 | time_t now, secs; | 427 | time_t now, secs; |
417 | 428 | ||
418 | if (!t) | 429 | if (!t) |
419 | return; | 430 | return; |
420 | time(&now); | 431 | time(&now); |