author | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 09:59:22 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 09:59:22 (UTC) |
commit | 681fdc45473143de3f3c5f69fbc7b94f5d6b0b75 (patch) (unidiff) | |
tree | 3bfca05875524bee0e5444fb791707bc3e593dbd /ui-shared.c | |
parent | 7e5c048505efe1902fb476cc2cb3160ff7df013d (diff) | |
parent | 3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f (diff) | |
download | cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.zip cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.tar.gz cgit-681fdc45473143de3f3c5f69fbc7b94f5d6b0b75.tar.bz2 |
Merge branch 'plain-etag'
Conflicts:
ui-shared.c
-rw-r--r-- | ui-shared.c | 6 |
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 | |||
@@ -374,207 +374,213 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
374 | html("</a>"); | 374 | html("</a>"); |
375 | } | 375 | } |
376 | 376 | ||
377 | 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, |
378 | char *rev) | 378 | char *rev) |
379 | { | 379 | { |
380 | reporevlink("patch", name, title, class, head, rev, NULL); | 380 | reporevlink("patch", name, title, class, head, rev, NULL); |
381 | } | 381 | } |
382 | 382 | ||
383 | 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, |
384 | char *path) | 384 | char *path) |
385 | { | 385 | { |
386 | reporevlink("stats", name, title, class, head, NULL, path); | 386 | reporevlink("stats", name, title, class, head, NULL, path); |
387 | } | 387 | } |
388 | 388 | ||
389 | void cgit_object_link(struct object *obj) | 389 | void cgit_object_link(struct object *obj) |
390 | { | 390 | { |
391 | char *page, *shortrev, *fullrev, *name; | 391 | char *page, *shortrev, *fullrev, *name; |
392 | 392 | ||
393 | fullrev = sha1_to_hex(obj->sha1); | 393 | fullrev = sha1_to_hex(obj->sha1); |
394 | shortrev = xstrdup(fullrev); | 394 | shortrev = xstrdup(fullrev); |
395 | shortrev[10] = '\0'; | 395 | shortrev[10] = '\0'; |
396 | if (obj->type == OBJ_COMMIT) { | 396 | if (obj->type == OBJ_COMMIT) { |
397 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 397 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
398 | ctx.qry.head, fullrev); | 398 | ctx.qry.head, fullrev); |
399 | return; | 399 | return; |
400 | } else if (obj->type == OBJ_TREE) | 400 | } else if (obj->type == OBJ_TREE) |
401 | page = "tree"; | 401 | page = "tree"; |
402 | else if (obj->type == OBJ_TAG) | 402 | else if (obj->type == OBJ_TAG) |
403 | page = "tag"; | 403 | page = "tag"; |
404 | else | 404 | else |
405 | page = "blob"; | 405 | page = "blob"; |
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 | ||
410 | 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) |
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 | ||
425 | 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) |
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 | ||
468 | void cgit_print_http_headers(struct cgit_context *ctx) | 468 | void 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 | ||
487 | void cgit_print_docstart(struct cgit_context *ctx) | 493 | void 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 | ||
521 | void cgit_print_docend() | 527 | void 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 | ||
535 | int print_branch_option(const char *refname, const unsigned char *sha1, | 541 | int 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 | ||
543 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 549 | int 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; |
549 | char buf[256], *url; | 555 | char buf[256], *url; |
550 | unsigned char fileid[20]; | 556 | unsigned char fileid[20]; |
551 | int *header = (int *)cb_data; | 557 | int *header = (int *)cb_data; |
552 | 558 | ||
553 | if (prefixcmp(refname, "refs/archives")) | 559 | if (prefixcmp(refname, "refs/archives")) |
554 | return 0; | 560 | return 0; |
555 | strncpy(buf, refname+14, sizeof(buf)); | 561 | strncpy(buf, refname+14, sizeof(buf)); |
556 | obj = parse_object(sha1); | 562 | obj = parse_object(sha1); |
557 | if (!obj) | 563 | if (!obj) |
558 | return 1; | 564 | return 1; |
559 | if (obj->type == OBJ_TAG) { | 565 | if (obj->type == OBJ_TAG) { |
560 | tag = lookup_tag(sha1); | 566 | tag = lookup_tag(sha1); |
561 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 567 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
562 | return 0; | 568 | return 0; |
563 | hashcpy(fileid, tag->tagged->sha1); | 569 | hashcpy(fileid, tag->tagged->sha1); |
564 | } else if (obj->type != OBJ_BLOB) { | 570 | } else if (obj->type != OBJ_BLOB) { |
565 | return 0; | 571 | return 0; |
566 | } else { | 572 | } else { |
567 | hashcpy(fileid, sha1); | 573 | hashcpy(fileid, sha1); |
568 | } | 574 | } |
569 | if (!*header) { | 575 | if (!*header) { |
570 | html("<h1>download</h1>\n"); | 576 | html("<h1>download</h1>\n"); |
571 | *header = 1; | 577 | *header = 1; |
572 | } | 578 | } |
573 | url = cgit_pageurl(ctx.qry.repo, "blob", | 579 | url = cgit_pageurl(ctx.qry.repo, "blob", |
574 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 580 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
575 | buf)); | 581 | buf)); |
576 | html_link_open(url, NULL, "menu"); | 582 | html_link_open(url, NULL, "menu"); |
577 | html_txt(strlpart(buf, 20)); | 583 | html_txt(strlpart(buf, 20)); |
578 | html_link_close(); | 584 | html_link_close(); |
579 | return 0; | 585 | return 0; |
580 | } | 586 | } |