-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 ca8dd3d..bd34cc3 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -394,140 +394,144 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, | |||
394 | unsigned char fileid[20]; | 394 | unsigned char fileid[20]; |
395 | int *header = (int *)cb_data; | 395 | int *header = (int *)cb_data; |
396 | 396 | ||
397 | if (prefixcmp(refname, "refs/archives")) | 397 | if (prefixcmp(refname, "refs/archives")) |
398 | return 0; | 398 | return 0; |
399 | strncpy(buf, refname+14, sizeof(buf)); | 399 | strncpy(buf, refname+14, sizeof(buf)); |
400 | obj = parse_object(sha1); | 400 | obj = parse_object(sha1); |
401 | if (!obj) | 401 | if (!obj) |
402 | return 1; | 402 | return 1; |
403 | if (obj->type == OBJ_TAG) { | 403 | if (obj->type == OBJ_TAG) { |
404 | tag = lookup_tag(sha1); | 404 | tag = lookup_tag(sha1); |
405 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 405 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
406 | return 0; | 406 | return 0; |
407 | hashcpy(fileid, tag->tagged->sha1); | 407 | hashcpy(fileid, tag->tagged->sha1); |
408 | } else if (obj->type != OBJ_BLOB) { | 408 | } else if (obj->type != OBJ_BLOB) { |
409 | return 0; | 409 | return 0; |
410 | } else { | 410 | } else { |
411 | hashcpy(fileid, sha1); | 411 | hashcpy(fileid, sha1); |
412 | } | 412 | } |
413 | if (!*header) { | 413 | if (!*header) { |
414 | html("<p><h1>download</h1>"); | 414 | html("<p><h1>download</h1>"); |
415 | *header = 1; | 415 | *header = 1; |
416 | } | 416 | } |
417 | url = cgit_pageurl(cgit_query_repo, "blob", | 417 | url = cgit_pageurl(cgit_query_repo, "blob", |
418 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 418 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
419 | buf)); | 419 | buf)); |
420 | html_link_open(url, NULL, "menu"); | 420 | html_link_open(url, NULL, "menu"); |
421 | html_txt(strlpart(buf, 20)); | 421 | html_txt(strlpart(buf, 20)); |
422 | html_link_close(); | 422 | html_link_close(); |
423 | return 0; | 423 | return 0; |
424 | } | 424 | } |
425 | 425 | ||
426 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 426 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
427 | { | 427 | { |
428 | char *url; | 428 | char *url; |
429 | 429 | ||
430 | if (!cgit_virtual_root) { | 430 | if (!cgit_virtual_root) { |
431 | url = fmt("%s/%s", cgit_query_repo, page); | 431 | url = fmt("%s/%s", cgit_query_repo, page); |
432 | if (cgit_query_path) | 432 | if (cgit_query_path) |
433 | url = fmt("%s/%s", url, cgit_query_path); | 433 | url = fmt("%s/%s", url, cgit_query_path); |
434 | html_hidden("url", url); | 434 | html_hidden("url", url); |
435 | } | 435 | } |
436 | 436 | ||
437 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) | 437 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) |
438 | html_hidden("h", cgit_query_head); | 438 | html_hidden("h", cgit_query_head); |
439 | 439 | ||
440 | if (cgit_query_sha1) | 440 | if (cgit_query_sha1) |
441 | html_hidden("id", cgit_query_sha1); | 441 | html_hidden("id", cgit_query_sha1); |
442 | if (cgit_query_sha2) | 442 | if (cgit_query_sha2) |
443 | html_hidden("id2", cgit_query_sha2); | 443 | html_hidden("id2", cgit_query_sha2); |
444 | 444 | ||
445 | if (incl_search) { | 445 | if (incl_search) { |
446 | if (cgit_query_grep) | 446 | if (cgit_query_grep) |
447 | html_hidden("qt", cgit_query_grep); | 447 | html_hidden("qt", cgit_query_grep); |
448 | if (cgit_query_search) | 448 | if (cgit_query_search) |
449 | html_hidden("q", cgit_query_search); | 449 | html_hidden("q", cgit_query_search); |
450 | } | 450 | } |
451 | } | 451 | } |
452 | 452 | ||
453 | void cgit_print_pageheader(char *title, int show_search) | 453 | void cgit_print_pageheader(char *title, int show_search) |
454 | { | 454 | { |
455 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | 455 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; |
456 | int header = 0; | 456 | int header = 0; |
457 | 457 | ||
458 | html("<div id='sidebar'>\n"); | 458 | html("<div id='sidebar'>\n"); |
459 | html("<a href='"); | 459 | html("<a href='"); |
460 | html_attr(cgit_rooturl()); | 460 | html_attr(cgit_rooturl()); |
461 | htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", | 461 | htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", |
462 | cgit_logo); | 462 | cgit_logo); |
463 | html("<div class='infobox'>"); | 463 | html("<div class='infobox'>"); |
464 | if (cgit_query_repo) { | 464 | if (cgit_query_repo) { |
465 | html("<h1>"); | 465 | html("<h1>"); |
466 | html_txt(strrpart(cgit_repo->name, 20)); | 466 | html_txt(strrpart(cgit_repo->name, 20)); |
467 | html("</h1>\n"); | 467 | html("</h1>\n"); |
468 | html_txt(cgit_repo->desc); | 468 | html_txt(cgit_repo->desc); |
469 | if (cgit_repo->owner) { | 469 | if (cgit_repo->owner) { |
470 | html("<p>\n<h1>owner</h1>\n"); | 470 | html("<p>\n<h1>owner</h1>\n"); |
471 | html_txt(cgit_repo->owner); | 471 | html_txt(cgit_repo->owner); |
472 | } | 472 | } |
473 | html("<p>\n<h1>navigate</h1>\n"); | 473 | html("<p>\n<h1>navigate</h1>\n"); |
474 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, | 474 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, |
475 | NULL, NULL); | 475 | NULL, NULL); |
476 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, | 476 | cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, |
477 | 0, NULL, NULL); | 477 | 0, NULL, NULL); |
478 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, | 478 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, |
479 | cgit_query_sha1, NULL); | 479 | cgit_query_sha1, NULL); |
480 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, | 480 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, |
481 | cgit_query_sha1); | 481 | cgit_query_sha1); |
482 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, | 482 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, |
483 | cgit_query_sha1, cgit_query_sha2, NULL); | 483 | cgit_query_sha1, cgit_query_sha2, NULL); |
484 | 484 | ||
485 | for_each_ref(print_archive_ref, &header); | 485 | for_each_ref(print_archive_ref, &header); |
486 | 486 | ||
487 | html("<p>\n<h1>branch</h1>\n"); | 487 | html("<p>\n<h1>branch</h1>\n"); |
488 | html("<form method='get' action=''>\n"); | 488 | html("<form method='get' action=''>\n"); |
489 | add_hidden_formfields(0, 1, cgit_query_page); | 489 | add_hidden_formfields(0, 1, cgit_query_page); |
490 | html("<table class='grid'><tr><td id='branch-dropdown-cell'>"); | ||
490 | html("<select name='h' onchange='this.form.submit();'>\n"); | 491 | html("<select name='h' onchange='this.form.submit();'>\n"); |
491 | for_each_branch_ref(print_branch_option, cgit_query_head); | 492 | for_each_branch_ref(print_branch_option, cgit_query_head); |
492 | html("</select>\n"); | 493 | html("</select>\n"); |
494 | html("</td><td>"); | ||
495 | html("<input type='submit' id='switch-btn' value='..'>\n"); | ||
496 | html("</td></tr></table>"); | ||
493 | html("</form>\n"); | 497 | html("</form>\n"); |
494 | 498 | ||
495 | html("<p>\n<h1>search</h1>\n"); | 499 | html("<p>\n<h1>search</h1>\n"); |
496 | html("<form method='get' action='"); | 500 | html("<form method='get' action='"); |
497 | if (cgit_virtual_root) | 501 | if (cgit_virtual_root) |
498 | html_attr(cgit_fileurl(cgit_query_repo, "log", | 502 | html_attr(cgit_fileurl(cgit_query_repo, "log", |
499 | cgit_query_path, NULL)); | 503 | cgit_query_path, NULL)); |
500 | html("'>\n"); | 504 | html("'>\n"); |
501 | add_hidden_formfields(1, 0, "log"); | 505 | add_hidden_formfields(1, 0, "log"); |
502 | html("<select name='qt'>\n"); | 506 | html("<select name='qt'>\n"); |
503 | html_option("grep", "log msg", cgit_query_grep); | 507 | html_option("grep", "log msg", cgit_query_grep); |
504 | html_option("author", "author", cgit_query_grep); | 508 | html_option("author", "author", cgit_query_grep); |
505 | html_option("committer", "committer", cgit_query_grep); | 509 | html_option("committer", "committer", cgit_query_grep); |
506 | html("</select>\n"); | 510 | html("</select>\n"); |
507 | html("<input class='txt' type='text' name='q' value='"); | 511 | html("<input class='txt' type='text' name='q' value='"); |
508 | html_attr(cgit_query_search); | 512 | html_attr(cgit_query_search); |
509 | html("'/>\n"); | 513 | html("'/>\n"); |
510 | html("</form>\n"); | 514 | html("</form>\n"); |
511 | } else { | 515 | } else { |
512 | if (!cgit_index_info || html_include(cgit_index_info)) | 516 | if (!cgit_index_info || html_include(cgit_index_info)) |
513 | html(default_info); | 517 | html(default_info); |
514 | } | 518 | } |
515 | 519 | ||
516 | html("</div>\n"); | 520 | html("</div>\n"); |
517 | 521 | ||
518 | html("</div>\n<table class='grid'><tr><td id='content'>\n"); | 522 | html("</div>\n<table class='grid'><tr><td id='content'>\n"); |
519 | } | 523 | } |
520 | 524 | ||
521 | 525 | ||
522 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 526 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
523 | struct cacheitem *item) | 527 | struct cacheitem *item) |
524 | { | 528 | { |
525 | htmlf("Content-Type: %s\n", mimetype); | 529 | htmlf("Content-Type: %s\n", mimetype); |
526 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 530 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
527 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 531 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
528 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 532 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
529 | ttl_seconds(item->ttl))); | 533 | ttl_seconds(item->ttl))); |
530 | html("\n"); | 534 | html("\n"); |
531 | } | 535 | } |
532 | 536 | ||
533 | /* vim:set sw=8: */ | 537 | /* vim:set sw=8: */ |