-rw-r--r-- | ui-shared.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/ui-shared.c b/ui-shared.c index b9f487a..cc1ab8b 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -351,220 +351,220 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
351 | secs * 1.0 / TM_WEEK); | 351 | secs * 1.0 / TM_WEEK); |
352 | return; | 352 | return; |
353 | } | 353 | } |
354 | if (secs < TM_YEAR * 2) { | 354 | if (secs < TM_YEAR * 2) { |
355 | htmlf("<span class='age-months'>%.0f months</span>", | 355 | htmlf("<span class='age-months'>%.0f months</span>", |
356 | secs * 1.0 / TM_MONTH); | 356 | secs * 1.0 / TM_MONTH); |
357 | return; | 357 | return; |
358 | } | 358 | } |
359 | htmlf("<span class='age-years'>%.0f years</span>", | 359 | htmlf("<span class='age-years'>%.0f years</span>", |
360 | secs * 1.0 / TM_YEAR); | 360 | secs * 1.0 / TM_YEAR); |
361 | } | 361 | } |
362 | 362 | ||
363 | void cgit_print_docstart(char *title, struct cacheitem *item) | 363 | void cgit_print_docstart(char *title, struct cacheitem *item) |
364 | { | 364 | { |
365 | html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); | 365 | html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); |
366 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 366 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
367 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 367 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
368 | ttl_seconds(item->ttl))); | 368 | ttl_seconds(item->ttl))); |
369 | html("\n"); | 369 | html("\n"); |
370 | html(cgit_doctype); | 370 | html(cgit_doctype); |
371 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 371 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
372 | html("<head>\n"); | 372 | html("<head>\n"); |
373 | html("<title>"); | 373 | html("<title>"); |
374 | html_txt(title); | 374 | html_txt(title); |
375 | html("</title>\n"); | 375 | html("</title>\n"); |
376 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 376 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
377 | if (ctx.cfg.robots && *ctx.cfg.robots) | 377 | if (ctx.cfg.robots && *ctx.cfg.robots) |
378 | htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); | 378 | htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); |
379 | html("<link rel='stylesheet' type='text/css' href='"); | 379 | html("<link rel='stylesheet' type='text/css' href='"); |
380 | html_attr(ctx.cfg.css); | 380 | html_attr(ctx.cfg.css); |
381 | html("'/>\n"); | 381 | html("'/>\n"); |
382 | html("</head>\n"); | 382 | html("</head>\n"); |
383 | html("<body>\n"); | 383 | html("<body>\n"); |
384 | } | 384 | } |
385 | 385 | ||
386 | void cgit_print_docend() | 386 | void cgit_print_docend() |
387 | { | 387 | { |
388 | html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); | 388 | html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); |
389 | } | 389 | } |
390 | 390 | ||
391 | int print_branch_option(const char *refname, const unsigned char *sha1, | 391 | int print_branch_option(const char *refname, const unsigned char *sha1, |
392 | int flags, void *cb_data) | 392 | int flags, void *cb_data) |
393 | { | 393 | { |
394 | char *name = (char *)refname; | 394 | char *name = (char *)refname; |
395 | html_option(name, name, ctx.qry.head); | 395 | html_option(name, name, ctx.qry.head); |
396 | return 0; | 396 | return 0; |
397 | } | 397 | } |
398 | 398 | ||
399 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 399 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
400 | int flags, void *cb_data) | 400 | int flags, void *cb_data) |
401 | { | 401 | { |
402 | struct tag *tag; | 402 | struct tag *tag; |
403 | struct taginfo *info; | 403 | struct taginfo *info; |
404 | struct object *obj; | 404 | struct object *obj; |
405 | char buf[256], *url; | 405 | char buf[256], *url; |
406 | unsigned char fileid[20]; | 406 | unsigned char fileid[20]; |
407 | int *header = (int *)cb_data; | 407 | int *header = (int *)cb_data; |
408 | 408 | ||
409 | if (prefixcmp(refname, "refs/archives")) | 409 | if (prefixcmp(refname, "refs/archives")) |
410 | return 0; | 410 | return 0; |
411 | strncpy(buf, refname+14, sizeof(buf)); | 411 | strncpy(buf, refname+14, sizeof(buf)); |
412 | obj = parse_object(sha1); | 412 | obj = parse_object(sha1); |
413 | if (!obj) | 413 | if (!obj) |
414 | return 1; | 414 | return 1; |
415 | if (obj->type == OBJ_TAG) { | 415 | if (obj->type == OBJ_TAG) { |
416 | tag = lookup_tag(sha1); | 416 | tag = lookup_tag(sha1); |
417 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 417 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
418 | return 0; | 418 | return 0; |
419 | hashcpy(fileid, tag->tagged->sha1); | 419 | hashcpy(fileid, tag->tagged->sha1); |
420 | } else if (obj->type != OBJ_BLOB) { | 420 | } else if (obj->type != OBJ_BLOB) { |
421 | return 0; | 421 | return 0; |
422 | } else { | 422 | } else { |
423 | hashcpy(fileid, sha1); | 423 | hashcpy(fileid, sha1); |
424 | } | 424 | } |
425 | if (!*header) { | 425 | if (!*header) { |
426 | html("<h1>download</h1>\n"); | 426 | html("<h1>download</h1>\n"); |
427 | *header = 1; | 427 | *header = 1; |
428 | } | 428 | } |
429 | url = cgit_pageurl(ctx.qry.repo, "blob", | 429 | url = cgit_pageurl(ctx.qry.repo, "blob", |
430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
431 | buf)); | 431 | buf)); |
432 | html_link_open(url, NULL, "menu"); | 432 | html_link_open(url, NULL, "menu"); |
433 | html_txt(strlpart(buf, 20)); | 433 | html_txt(strlpart(buf, 20)); |
434 | html_link_close(); | 434 | html_link_close(); |
435 | return 0; | 435 | return 0; |
436 | } | 436 | } |
437 | 437 | ||
438 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 438 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
439 | { | 439 | { |
440 | char *url; | 440 | char *url; |
441 | 441 | ||
442 | if (!ctx.cfg.virtual_root) { | 442 | if (!ctx.cfg.virtual_root) { |
443 | url = fmt("%s/%s", ctx.qry.repo, page); | 443 | url = fmt("%s/%s", ctx.qry.repo, page); |
444 | if (ctx.qry.path) | 444 | if (ctx.qry.path) |
445 | url = fmt("%s/%s", url, ctx.qry.path); | 445 | url = fmt("%s/%s", url, ctx.qry.path); |
446 | html_hidden("url", url); | 446 | html_hidden("url", url); |
447 | } | 447 | } |
448 | 448 | ||
449 | if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) | 449 | if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) |
450 | html_hidden("h", ctx.qry.head); | 450 | html_hidden("h", ctx.qry.head); |
451 | 451 | ||
452 | if (ctx.qry.sha1) | 452 | if (ctx.qry.sha1) |
453 | html_hidden("id", ctx.qry.sha1); | 453 | html_hidden("id", ctx.qry.sha1); |
454 | if (ctx.qry.sha2) | 454 | if (ctx.qry.sha2) |
455 | html_hidden("id2", ctx.qry.sha2); | 455 | html_hidden("id2", ctx.qry.sha2); |
456 | 456 | ||
457 | if (incl_search) { | 457 | if (incl_search) { |
458 | if (ctx.qry.grep) | 458 | if (ctx.qry.grep) |
459 | html_hidden("qt", ctx.qry.grep); | 459 | html_hidden("qt", ctx.qry.grep); |
460 | if (ctx.qry.search) | 460 | if (ctx.qry.search) |
461 | html_hidden("q", ctx.qry.search); | 461 | html_hidden("q", ctx.qry.search); |
462 | } | 462 | } |
463 | } | 463 | } |
464 | 464 | ||
465 | void cgit_print_pageheader(char *title, int show_search) | 465 | void cgit_print_pageheader(char *title, int show_search) |
466 | { | 466 | { |
467 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | 467 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; |
468 | int header = 0; | 468 | int header = 0; |
469 | char *url; | 469 | char *url; |
470 | 470 | ||
471 | html("<table id='layout' summary=''>\n"); | 471 | html("<table id='layout' summary=''>\n"); |
472 | html("<tr><td id='sidebar'>\n"); | 472 | html("<tr><td id='sidebar'>\n"); |
473 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); | 473 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); |
474 | html("<tr><td class='sidebar'>\n<a href='"); | 474 | html("<tr><td class='sidebar'>\n<a href='"); |
475 | html_attr(cgit_rooturl()); | 475 | html_attr(cgit_rooturl()); |
476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", | 476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", |
477 | ctx.cfg.logo); | 477 | ctx.cfg.logo); |
478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
479 | if (ctx.qry.repo) { | 479 | if (ctx.repo) { |
480 | html("<h1 class='first'>"); | 480 | html("<h1 class='first'>"); |
481 | html_txt(strrpart(ctx.repo->name, 20)); | 481 | html_txt(strrpart(ctx.repo->name, 20)); |
482 | html("</h1>\n"); | 482 | html("</h1>\n"); |
483 | html_txt(ctx.repo->desc); | 483 | html_txt(ctx.repo->desc); |
484 | if (ctx.repo->owner) { | 484 | if (ctx.repo->owner) { |
485 | html("<h1>owner</h1>\n"); | 485 | html("<h1>owner</h1>\n"); |
486 | html_txt(ctx.repo->owner); | 486 | html_txt(ctx.repo->owner); |
487 | } | 487 | } |
488 | html("<h1>navigate</h1>\n"); | 488 | html("<h1>navigate</h1>\n"); |
489 | reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, | 489 | reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, |
490 | NULL, NULL); | 490 | NULL, NULL); |
491 | cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, | 491 | cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, |
492 | 0, NULL, NULL); | 492 | 0, NULL, NULL); |
493 | cgit_tree_link("tree", NULL, "menu", ctx.qry.head, | 493 | cgit_tree_link("tree", NULL, "menu", ctx.qry.head, |
494 | ctx.qry.sha1, NULL); | 494 | ctx.qry.sha1, NULL); |
495 | cgit_commit_link("commit", NULL, "menu", ctx.qry.head, | 495 | cgit_commit_link("commit", NULL, "menu", ctx.qry.head, |
496 | ctx.qry.sha1); | 496 | ctx.qry.sha1); |
497 | cgit_diff_link("diff", NULL, "menu", ctx.qry.head, | 497 | cgit_diff_link("diff", NULL, "menu", ctx.qry.head, |
498 | ctx.qry.sha1, ctx.qry.sha2, NULL); | 498 | ctx.qry.sha1, ctx.qry.sha2, NULL); |
499 | cgit_patch_link("patch", NULL, "menu", ctx.qry.head, | 499 | cgit_patch_link("patch", NULL, "menu", ctx.qry.head, |
500 | ctx.qry.sha1); | 500 | ctx.qry.sha1); |
501 | 501 | ||
502 | for_each_ref(print_archive_ref, &header); | 502 | for_each_ref(print_archive_ref, &header); |
503 | 503 | ||
504 | if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { | 504 | if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { |
505 | html("<h1>clone</h1>\n"); | 505 | html("<h1>clone</h1>\n"); |
506 | if (ctx.repo->clone_url) | 506 | if (ctx.repo->clone_url) |
507 | url = ctx.repo->clone_url; | 507 | url = ctx.repo->clone_url; |
508 | else | 508 | else |
509 | url = fmt("%s%s", ctx.cfg.clone_prefix, | 509 | url = fmt("%s%s", ctx.cfg.clone_prefix, |
510 | ctx.repo->url); | 510 | ctx.repo->url); |
511 | html("<a class='menu' href='"); | 511 | html("<a class='menu' href='"); |
512 | html_attr(url); | 512 | html_attr(url); |
513 | html("' title='"); | 513 | html("' title='"); |
514 | html_attr(url); | 514 | html_attr(url); |
515 | html("'>\n"); | 515 | html("'>\n"); |
516 | html_txt(strrpart(url, 20)); | 516 | html_txt(strrpart(url, 20)); |
517 | html("</a>\n"); | 517 | html("</a>\n"); |
518 | } | 518 | } |
519 | 519 | ||
520 | html("<h1>branch</h1>\n"); | 520 | html("<h1>branch</h1>\n"); |
521 | html("<form method='get' action=''>\n"); | 521 | html("<form method='get' action=''>\n"); |
522 | add_hidden_formfields(0, 1, ctx.qry.page); | 522 | add_hidden_formfields(0, 1, ctx.qry.page); |
523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); | 523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); |
524 | html("<select name='h' onchange='this.form.submit();'>\n"); | 524 | html("<select name='h' onchange='this.form.submit();'>\n"); |
525 | for_each_branch_ref(print_branch_option, ctx.qry.head); | 525 | for_each_branch_ref(print_branch_option, ctx.qry.head); |
526 | html("</select>\n"); | 526 | html("</select>\n"); |
527 | // html("</td><td>"); | 527 | // html("</td><td>"); |
528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); | 528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); |
529 | // html("</td></tr></table>"); | 529 | // html("</td></tr></table>"); |
530 | html("</form>\n"); | 530 | html("</form>\n"); |
531 | 531 | ||
532 | html("<h1>search</h1>\n"); | 532 | html("<h1>search</h1>\n"); |
533 | html("<form method='get' action='"); | 533 | html("<form method='get' action='"); |
534 | if (ctx.cfg.virtual_root) | 534 | if (ctx.cfg.virtual_root) |
535 | html_attr(cgit_fileurl(ctx.qry.repo, "log", | 535 | html_attr(cgit_fileurl(ctx.qry.repo, "log", |
536 | ctx.qry.path, NULL)); | 536 | ctx.qry.path, NULL)); |
537 | html("'>\n"); | 537 | html("'>\n"); |
538 | add_hidden_formfields(1, 0, "log"); | 538 | add_hidden_formfields(1, 0, "log"); |
539 | html("<select name='qt'>\n"); | 539 | html("<select name='qt'>\n"); |
540 | html_option("grep", "log msg", ctx.qry.grep); | 540 | html_option("grep", "log msg", ctx.qry.grep); |
541 | html_option("author", "author", ctx.qry.grep); | 541 | html_option("author", "author", ctx.qry.grep); |
542 | html_option("committer", "committer", ctx.qry.grep); | 542 | html_option("committer", "committer", ctx.qry.grep); |
543 | html("</select>\n"); | 543 | html("</select>\n"); |
544 | html("<input class='txt' type='text' name='q' value='"); | 544 | html("<input class='txt' type='text' name='q' value='"); |
545 | html_attr(ctx.qry.search); | 545 | html_attr(ctx.qry.search); |
546 | html("'/>\n"); | 546 | html("'/>\n"); |
547 | html("</form>\n"); | 547 | html("</form>\n"); |
548 | } else { | 548 | } else { |
549 | if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) | 549 | if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) |
550 | html(default_info); | 550 | html(default_info); |
551 | } | 551 | } |
552 | 552 | ||
553 | html("</td></tr></table></td>\n"); | 553 | html("</td></tr></table></td>\n"); |
554 | 554 | ||
555 | html("<td id='content'>\n"); | 555 | html("<td id='content'>\n"); |
556 | } | 556 | } |
557 | 557 | ||
558 | 558 | ||
559 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 559 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
560 | struct cacheitem *item) | 560 | struct cacheitem *item) |
561 | { | 561 | { |
562 | htmlf("Content-Type: %s\n", mimetype); | 562 | htmlf("Content-Type: %s\n", mimetype); |
563 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 563 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
564 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 564 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
565 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 565 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
566 | ttl_seconds(item->ttl))); | 566 | ttl_seconds(item->ttl))); |
567 | html("\n"); | 567 | html("\n"); |
568 | } | 568 | } |
569 | 569 | ||
570 | /* vim:set sw=8: */ | 570 | /* vim:set sw=8: */ |