summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2009-07-25 09:59:22 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-07-25 09:59:22 (UTC)
commit681fdc45473143de3f3c5f69fbc7b94f5d6b0b75 (patch) (unidiff)
tree3bfca05875524bee0e5444fb791707bc3e593dbd /ui-shared.c
parent7e5c048505efe1902fb476cc2cb3160ff7df013d (diff)
parent3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f (diff)
downloadcgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.zip
cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.tar.gz
cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.tar.bz2
Merge branch 'plain-etag'
Conflicts: ui-shared.c
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 29036d0..10be3c0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -406,143 +406,149 @@ void cgit_object_link(struct object *obj)
406 name = fmt("%s %s...", typename(obj->type), shortrev); 406 name = fmt("%s %s...", typename(obj->type), shortrev);
407 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 407 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
408} 408}
409 409
410void cgit_print_date(time_t secs, char *format, int local_time) 410void cgit_print_date(time_t secs, char *format, int local_time)
411{ 411{
412 char buf[64]; 412 char buf[64];
413 struct tm *time; 413 struct tm *time;
414 414
415 if (!secs) 415 if (!secs)
416 return; 416 return;
417 if(local_time) 417 if(local_time)
418 time = localtime(&secs); 418 time = localtime(&secs);
419 else 419 else
420 time = gmtime(&secs); 420 time = gmtime(&secs);
421 strftime(buf, sizeof(buf)-1, format, time); 421 strftime(buf, sizeof(buf)-1, format, time);
422 html_txt(buf); 422 html_txt(buf);
423} 423}
424 424
425void cgit_print_age(time_t t, time_t max_relative, char *format) 425void cgit_print_age(time_t t, time_t max_relative, char *format)
426{ 426{
427 time_t now, secs; 427 time_t now, secs;
428 428
429 if (!t) 429 if (!t)
430 return; 430 return;
431 time(&now); 431 time(&now);
432 secs = now - t; 432 secs = now - t;
433 433
434 if (secs > max_relative && max_relative >= 0) { 434 if (secs > max_relative && max_relative >= 0) {
435 cgit_print_date(t, format, ctx.cfg.local_time); 435 cgit_print_date(t, format, ctx.cfg.local_time);
436 return; 436 return;
437 } 437 }
438 438
439 if (secs < TM_HOUR * 2) { 439 if (secs < TM_HOUR * 2) {
440 htmlf("<span class='age-mins'>%.0f min.</span>", 440 htmlf("<span class='age-mins'>%.0f min.</span>",
441 secs * 1.0 / TM_MIN); 441 secs * 1.0 / TM_MIN);
442 return; 442 return;
443 } 443 }
444 if (secs < TM_DAY * 2) { 444 if (secs < TM_DAY * 2) {
445 htmlf("<span class='age-hours'>%.0f hours</span>", 445 htmlf("<span class='age-hours'>%.0f hours</span>",
446 secs * 1.0 / TM_HOUR); 446 secs * 1.0 / TM_HOUR);
447 return; 447 return;
448 } 448 }
449 if (secs < TM_WEEK * 2) { 449 if (secs < TM_WEEK * 2) {
450 htmlf("<span class='age-days'>%.0f days</span>", 450 htmlf("<span class='age-days'>%.0f days</span>",
451 secs * 1.0 / TM_DAY); 451 secs * 1.0 / TM_DAY);
452 return; 452 return;
453 } 453 }
454 if (secs < TM_MONTH * 2) { 454 if (secs < TM_MONTH * 2) {
455 htmlf("<span class='age-weeks'>%.0f weeks</span>", 455 htmlf("<span class='age-weeks'>%.0f weeks</span>",
456 secs * 1.0 / TM_WEEK); 456 secs * 1.0 / TM_WEEK);
457 return; 457 return;
458 } 458 }
459 if (secs < TM_YEAR * 2) { 459 if (secs < TM_YEAR * 2) {
460 htmlf("<span class='age-months'>%.0f months</span>", 460 htmlf("<span class='age-months'>%.0f months</span>",
461 secs * 1.0 / TM_MONTH); 461 secs * 1.0 / TM_MONTH);
462 return; 462 return;
463 } 463 }
464 htmlf("<span class='age-years'>%.0f years</span>", 464 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR); 465 secs * 1.0 / TM_YEAR);
466} 466}
467 467
468void cgit_print_http_headers(struct cgit_context *ctx) 468void cgit_print_http_headers(struct cgit_context *ctx)
469{ 469{
470 const char *method = getenv("REQUEST_METHOD");
471
470 if (ctx->page.status) 472 if (ctx->page.status)
471 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 473 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
472 if (ctx->page.mimetype && ctx->page.charset) 474 if (ctx->page.mimetype && ctx->page.charset)
473 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 475 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
474 ctx->page.charset); 476 ctx->page.charset);
475 else if (ctx->page.mimetype) 477 else if (ctx->page.mimetype)
476 htmlf("Content-Type: %s\n", ctx->page.mimetype); 478 htmlf("Content-Type: %s\n", ctx->page.mimetype);
477 if (ctx->page.size) 479 if (ctx->page.size)
478 htmlf("Content-Length: %ld\n", ctx->page.size); 480 htmlf("Content-Length: %ld\n", ctx->page.size);
479 if (ctx->page.filename) 481 if (ctx->page.filename)
480 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 482 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
481 ctx->page.filename); 483 ctx->page.filename);
482 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 484 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
483 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 485 htmlf("Expires: %s\n", http_date(ctx->page.expires));
486 if (ctx->page.etag)
487 htmlf("ETag: \"%s\"\n", ctx->page.etag);
484 html("\n"); 488 html("\n");
489 if (method && !strcmp(method, "HEAD"))
490 exit(0);
485} 491}
486 492
487void cgit_print_docstart(struct cgit_context *ctx) 493void cgit_print_docstart(struct cgit_context *ctx)
488{ 494{
489 char *host = cgit_hosturl(); 495 char *host = cgit_hosturl();
490 html(cgit_doctype); 496 html(cgit_doctype);
491 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 497 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
492 html("<head>\n"); 498 html("<head>\n");
493 html("<title>"); 499 html("<title>");
494 html_txt(ctx->page.title); 500 html_txt(ctx->page.title);
495 html("</title>\n"); 501 html("</title>\n");
496 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 502 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
497 if (ctx->cfg.robots && *ctx->cfg.robots) 503 if (ctx->cfg.robots && *ctx->cfg.robots)
498 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 504 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
499 html("<link rel='stylesheet' type='text/css' href='"); 505 html("<link rel='stylesheet' type='text/css' href='");
500 html_attr(ctx->cfg.css); 506 html_attr(ctx->cfg.css);
501 html("'/>\n"); 507 html("'/>\n");
502 if (ctx->cfg.favicon) { 508 if (ctx->cfg.favicon) {
503 html("<link rel='shortcut icon' href='"); 509 html("<link rel='shortcut icon' href='");
504 html_attr(ctx->cfg.favicon); 510 html_attr(ctx->cfg.favicon);
505 html("'/>\n"); 511 html("'/>\n");
506 } 512 }
507 if (host && ctx->repo) { 513 if (host && ctx->repo) {
508 html("<link rel='alternate' title='Atom feed' href='"); 514 html("<link rel='alternate' title='Atom feed' href='");
509 html(cgit_httpscheme()); 515 html(cgit_httpscheme());
510 html_attr(cgit_hosturl()); 516 html_attr(cgit_hosturl());
511 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, 517 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
512 fmt("h=%s", ctx->qry.head))); 518 fmt("h=%s", ctx->qry.head)));
513 html("' type='application/atom+xml'/>"); 519 html("' type='application/atom+xml'/>");
514 } 520 }
515 html("</head>\n"); 521 html("</head>\n");
516 html("<body>\n"); 522 html("<body>\n");
517 if (ctx->cfg.header) 523 if (ctx->cfg.header)
518 html_include(ctx->cfg.header); 524 html_include(ctx->cfg.header);
519} 525}
520 526
521void cgit_print_docend() 527void cgit_print_docend()
522{ 528{
523 html("</div>"); 529 html("</div>");
524 if (ctx.cfg.footer) 530 if (ctx.cfg.footer)
525 html_include(ctx.cfg.footer); 531 html_include(ctx.cfg.footer);
526 else { 532 else {
527 htmlf("<div class='footer'>generated by cgit %s at ", 533 htmlf("<div class='footer'>generated by cgit %s at ",
528 cgit_version); 534 cgit_version);
529 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); 535 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
530 html("</div>\n"); 536 html("</div>\n");
531 } 537 }
532 html("</body>\n</html>\n"); 538 html("</body>\n</html>\n");
533} 539}
534 540
535int print_branch_option(const char *refname, const unsigned char *sha1, 541int print_branch_option(const char *refname, const unsigned char *sha1,
536 int flags, void *cb_data) 542 int flags, void *cb_data)
537{ 543{
538 char *name = (char *)refname; 544 char *name = (char *)refname;
539 html_option(name, name, ctx.qry.head); 545 html_option(name, name, ctx.qry.head);
540 return 0; 546 return 0;
541} 547}
542 548
543int print_archive_ref(const char *refname, const unsigned char *sha1, 549int print_archive_ref(const char *refname, const unsigned char *sha1,
544 int flags, void *cb_data) 550 int flags, void *cb_data)
545{ 551{
546 struct tag *tag; 552 struct tag *tag;
547 struct taginfo *info; 553 struct taginfo *info;
548 struct object *obj; 554 struct object *obj;