-rw-r--r-- | ui-shared.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index be2c75d..3e13c86 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -259,105 +259,109 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
259 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 259 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
260 | html(delim); | 260 | html(delim); |
261 | html("id="); | 261 | html("id="); |
262 | html_attr(new_rev); | 262 | html_attr(new_rev); |
263 | delim = "&"; | 263 | delim = "&"; |
264 | } | 264 | } |
265 | if (old_rev) { | 265 | if (old_rev) { |
266 | html(delim); | 266 | html(delim); |
267 | html("id2="); | 267 | html("id2="); |
268 | html_attr(old_rev); | 268 | html_attr(old_rev); |
269 | } | 269 | } |
270 | html("'>"); | 270 | html("'>"); |
271 | html_txt(name); | 271 | html_txt(name); |
272 | html("</a>"); | 272 | html("</a>"); |
273 | } | 273 | } |
274 | 274 | ||
275 | void cgit_object_link(struct object *obj) | 275 | void cgit_object_link(struct object *obj) |
276 | { | 276 | { |
277 | char *page, *arg, *url; | 277 | char *page, *arg, *url; |
278 | 278 | ||
279 | if (obj->type == OBJ_COMMIT) { | 279 | if (obj->type == OBJ_COMMIT) { |
280 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 280 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
281 | cgit_query_head, sha1_to_hex(obj->sha1)); | 281 | cgit_query_head, sha1_to_hex(obj->sha1)); |
282 | return; | 282 | return; |
283 | } else if (obj->type == OBJ_TREE) { | 283 | } else if (obj->type == OBJ_TREE) { |
284 | page = "tree"; | 284 | page = "tree"; |
285 | arg = "id"; | 285 | arg = "id"; |
286 | } else if (obj->type == OBJ_TAG) { | 286 | } else if (obj->type == OBJ_TAG) { |
287 | page = "tag"; | 287 | page = "tag"; |
288 | arg = "id"; | 288 | arg = "id"; |
289 | } else { | 289 | } else { |
290 | page = "blob"; | 290 | page = "blob"; |
291 | arg = "id"; | 291 | arg = "id"; |
292 | } | 292 | } |
293 | 293 | ||
294 | url = cgit_pageurl(cgit_query_repo, page, | 294 | url = cgit_pageurl(cgit_query_repo, page, |
295 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 295 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
296 | html_link_open(url, NULL, NULL); | 296 | html_link_open(url, NULL, NULL); |
297 | htmlf("%s %s", typename(obj->type), | 297 | htmlf("%s %s", typename(obj->type), |
298 | sha1_to_hex(obj->sha1)); | 298 | sha1_to_hex(obj->sha1)); |
299 | html_link_close(); | 299 | html_link_close(); |
300 | } | 300 | } |
301 | 301 | ||
302 | void cgit_print_date(time_t secs, char *format) | 302 | void cgit_print_date(time_t secs, char *format) |
303 | { | 303 | { |
304 | char buf[64]; | 304 | char buf[64]; |
305 | struct tm *time; | 305 | struct tm *time; |
306 | 306 | ||
307 | if (!secs) | ||
308 | return; | ||
307 | time = gmtime(&secs); | 309 | time = gmtime(&secs); |
308 | strftime(buf, sizeof(buf)-1, format, time); | 310 | strftime(buf, sizeof(buf)-1, format, time); |
309 | html_txt(buf); | 311 | html_txt(buf); |
310 | } | 312 | } |
311 | 313 | ||
312 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 314 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
313 | { | 315 | { |
314 | time_t now, secs; | 316 | time_t now, secs; |
315 | 317 | ||
318 | if (!t) | ||
319 | return; | ||
316 | time(&now); | 320 | time(&now); |
317 | secs = now - t; | 321 | secs = now - t; |
318 | 322 | ||
319 | if (secs > max_relative && max_relative >= 0) { | 323 | if (secs > max_relative && max_relative >= 0) { |
320 | cgit_print_date(t, format); | 324 | cgit_print_date(t, format); |
321 | return; | 325 | return; |
322 | } | 326 | } |
323 | 327 | ||
324 | if (secs < TM_HOUR * 2) { | 328 | if (secs < TM_HOUR * 2) { |
325 | htmlf("<span class='age-mins'>%.0f min.</span>", | 329 | htmlf("<span class='age-mins'>%.0f min.</span>", |
326 | secs * 1.0 / TM_MIN); | 330 | secs * 1.0 / TM_MIN); |
327 | return; | 331 | return; |
328 | } | 332 | } |
329 | if (secs < TM_DAY * 2) { | 333 | if (secs < TM_DAY * 2) { |
330 | htmlf("<span class='age-hours'>%.0f hours</span>", | 334 | htmlf("<span class='age-hours'>%.0f hours</span>", |
331 | secs * 1.0 / TM_HOUR); | 335 | secs * 1.0 / TM_HOUR); |
332 | return; | 336 | return; |
333 | } | 337 | } |
334 | if (secs < TM_WEEK * 2) { | 338 | if (secs < TM_WEEK * 2) { |
335 | htmlf("<span class='age-days'>%.0f days</span>", | 339 | htmlf("<span class='age-days'>%.0f days</span>", |
336 | secs * 1.0 / TM_DAY); | 340 | secs * 1.0 / TM_DAY); |
337 | return; | 341 | return; |
338 | } | 342 | } |
339 | if (secs < TM_MONTH * 2) { | 343 | if (secs < TM_MONTH * 2) { |
340 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 344 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
341 | secs * 1.0 / TM_WEEK); | 345 | secs * 1.0 / TM_WEEK); |
342 | return; | 346 | return; |
343 | } | 347 | } |
344 | if (secs < TM_YEAR * 2) { | 348 | if (secs < TM_YEAR * 2) { |
345 | htmlf("<span class='age-months'>%.0f months</span>", | 349 | htmlf("<span class='age-months'>%.0f months</span>", |
346 | secs * 1.0 / TM_MONTH); | 350 | secs * 1.0 / TM_MONTH); |
347 | return; | 351 | return; |
348 | } | 352 | } |
349 | htmlf("<span class='age-years'>%.0f years</span>", | 353 | htmlf("<span class='age-years'>%.0f years</span>", |
350 | secs * 1.0 / TM_YEAR); | 354 | secs * 1.0 / TM_YEAR); |
351 | } | 355 | } |
352 | 356 | ||
353 | void cgit_print_docstart(char *title, struct cacheitem *item) | 357 | void cgit_print_docstart(char *title, struct cacheitem *item) |
354 | { | 358 | { |
355 | html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); | 359 | html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); |
356 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 360 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
357 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 361 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
358 | ttl_seconds(item->ttl))); | 362 | ttl_seconds(item->ttl))); |
359 | html("\n"); | 363 | html("\n"); |
360 | html(cgit_doctype); | 364 | html(cgit_doctype); |
361 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 365 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
362 | html("<head>\n"); | 366 | html("<head>\n"); |
363 | html("<title>"); | 367 | html("<title>"); |