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 | |||
@@ -278,399 +278,405 @@ void cgit_tag_link(char *name, char *title, char *class, char *head, | |||
278 | { | 278 | { |
279 | reporevlink("tag", name, title, class, head, rev, NULL); | 279 | reporevlink("tag", name, title, class, head, rev, NULL); |
280 | } | 280 | } |
281 | 281 | ||
282 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 282 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
283 | char *rev, char *path) | 283 | char *rev, char *path) |
284 | { | 284 | { |
285 | reporevlink("tree", name, title, class, head, rev, path); | 285 | reporevlink("tree", name, title, class, head, rev, path); |
286 | } | 286 | } |
287 | 287 | ||
288 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 288 | void cgit_plain_link(char *name, char *title, char *class, char *head, |
289 | char *rev, char *path) | 289 | char *rev, char *path) |
290 | { | 290 | { |
291 | reporevlink("plain", name, title, class, head, rev, path); | 291 | reporevlink("plain", name, title, class, head, rev, path); |
292 | } | 292 | } |
293 | 293 | ||
294 | void cgit_log_link(char *name, char *title, char *class, char *head, | 294 | void cgit_log_link(char *name, char *title, char *class, char *head, |
295 | char *rev, char *path, int ofs, char *grep, char *pattern, | 295 | char *rev, char *path, int ofs, char *grep, char *pattern, |
296 | int showmsg) | 296 | int showmsg) |
297 | { | 297 | { |
298 | char *delim; | 298 | char *delim; |
299 | 299 | ||
300 | delim = repolink(title, class, "log", head, path); | 300 | delim = repolink(title, class, "log", head, path); |
301 | if (rev && strcmp(rev, ctx.qry.head)) { | 301 | if (rev && strcmp(rev, ctx.qry.head)) { |
302 | html(delim); | 302 | html(delim); |
303 | html("id="); | 303 | html("id="); |
304 | html_url_arg(rev); | 304 | html_url_arg(rev); |
305 | delim = "&"; | 305 | delim = "&"; |
306 | } | 306 | } |
307 | if (grep && pattern) { | 307 | if (grep && pattern) { |
308 | html(delim); | 308 | html(delim); |
309 | html("qt="); | 309 | html("qt="); |
310 | html_url_arg(grep); | 310 | html_url_arg(grep); |
311 | delim = "&"; | 311 | delim = "&"; |
312 | html(delim); | 312 | html(delim); |
313 | html("q="); | 313 | html("q="); |
314 | html_url_arg(pattern); | 314 | html_url_arg(pattern); |
315 | } | 315 | } |
316 | if (ofs > 0) { | 316 | if (ofs > 0) { |
317 | html(delim); | 317 | html(delim); |
318 | html("ofs="); | 318 | html("ofs="); |
319 | htmlf("%d", ofs); | 319 | htmlf("%d", ofs); |
320 | delim = "&"; | 320 | delim = "&"; |
321 | } | 321 | } |
322 | if (showmsg) { | 322 | if (showmsg) { |
323 | html(delim); | 323 | html(delim); |
324 | html("showmsg=1"); | 324 | html("showmsg=1"); |
325 | } | 325 | } |
326 | html("'>"); | 326 | html("'>"); |
327 | html_txt(name); | 327 | html_txt(name); |
328 | html("</a>"); | 328 | html("</a>"); |
329 | } | 329 | } |
330 | 330 | ||
331 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 331 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
332 | char *rev) | 332 | char *rev) |
333 | { | 333 | { |
334 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 334 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
335 | name[ctx.cfg.max_msg_len] = '\0'; | 335 | name[ctx.cfg.max_msg_len] = '\0'; |
336 | name[ctx.cfg.max_msg_len - 1] = '.'; | 336 | name[ctx.cfg.max_msg_len - 1] = '.'; |
337 | name[ctx.cfg.max_msg_len - 2] = '.'; | 337 | name[ctx.cfg.max_msg_len - 2] = '.'; |
338 | name[ctx.cfg.max_msg_len - 3] = '.'; | 338 | name[ctx.cfg.max_msg_len - 3] = '.'; |
339 | } | 339 | } |
340 | reporevlink("commit", name, title, class, head, rev, NULL); | 340 | reporevlink("commit", name, title, class, head, rev, NULL); |
341 | } | 341 | } |
342 | 342 | ||
343 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 343 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
344 | char *rev, char *path) | 344 | char *rev, char *path) |
345 | { | 345 | { |
346 | reporevlink("refs", name, title, class, head, rev, path); | 346 | reporevlink("refs", name, title, class, head, rev, path); |
347 | } | 347 | } |
348 | 348 | ||
349 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 349 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
350 | char *rev, char *archivename) | 350 | char *rev, char *archivename) |
351 | { | 351 | { |
352 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 352 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
353 | } | 353 | } |
354 | 354 | ||
355 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 355 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
356 | char *new_rev, char *old_rev, char *path) | 356 | char *new_rev, char *old_rev, char *path) |
357 | { | 357 | { |
358 | char *delim; | 358 | char *delim; |
359 | 359 | ||
360 | delim = repolink(title, class, "diff", head, path); | 360 | delim = repolink(title, class, "diff", head, path); |
361 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 361 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
362 | html(delim); | 362 | html(delim); |
363 | html("id="); | 363 | html("id="); |
364 | html_url_arg(new_rev); | 364 | html_url_arg(new_rev); |
365 | delim = "&"; | 365 | delim = "&"; |
366 | } | 366 | } |
367 | if (old_rev) { | 367 | if (old_rev) { |
368 | html(delim); | 368 | html(delim); |
369 | html("id2="); | 369 | html("id2="); |
370 | html_url_arg(old_rev); | 370 | html_url_arg(old_rev); |
371 | } | 371 | } |
372 | html("'>"); | 372 | html("'>"); |
373 | html_txt(name); | 373 | html_txt(name); |
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 | } |
581 | 587 | ||
582 | void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page) | 588 | void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page) |
583 | { | 589 | { |
584 | char *url; | 590 | char *url; |
585 | 591 | ||
586 | if (!ctx.cfg.virtual_root) { | 592 | if (!ctx.cfg.virtual_root) { |
587 | url = fmt("%s/%s", ctx.qry.repo, page); | 593 | url = fmt("%s/%s", ctx.qry.repo, page); |
588 | if (ctx.qry.path) | 594 | if (ctx.qry.path) |
589 | url = fmt("%s/%s", url, ctx.qry.path); | 595 | url = fmt("%s/%s", url, ctx.qry.path); |
590 | html_hidden("url", url); | 596 | html_hidden("url", url); |
591 | } | 597 | } |
592 | 598 | ||
593 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 599 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
594 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 600 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
595 | html_hidden("h", ctx.qry.head); | 601 | html_hidden("h", ctx.qry.head); |
596 | 602 | ||
597 | if (ctx.qry.sha1) | 603 | if (ctx.qry.sha1) |
598 | html_hidden("id", ctx.qry.sha1); | 604 | html_hidden("id", ctx.qry.sha1); |
599 | if (ctx.qry.sha2) | 605 | if (ctx.qry.sha2) |
600 | html_hidden("id2", ctx.qry.sha2); | 606 | html_hidden("id2", ctx.qry.sha2); |
601 | if (ctx.qry.showmsg) | 607 | if (ctx.qry.showmsg) |
602 | html_hidden("showmsg", "1"); | 608 | html_hidden("showmsg", "1"); |
603 | 609 | ||
604 | if (incl_search) { | 610 | if (incl_search) { |
605 | if (ctx.qry.grep) | 611 | if (ctx.qry.grep) |
606 | html_hidden("qt", ctx.qry.grep); | 612 | html_hidden("qt", ctx.qry.grep); |
607 | if (ctx.qry.search) | 613 | if (ctx.qry.search) |
608 | html_hidden("q", ctx.qry.search); | 614 | html_hidden("q", ctx.qry.search); |
609 | } | 615 | } |
610 | } | 616 | } |
611 | 617 | ||
612 | const char *fallback_cmd = "repolist"; | 618 | const char *fallback_cmd = "repolist"; |
613 | 619 | ||
614 | char *hc(struct cgit_cmd *cmd, const char *page) | 620 | char *hc(struct cgit_cmd *cmd, const char *page) |
615 | { | 621 | { |
616 | return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active"); | 622 | return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active"); |
617 | } | 623 | } |
618 | 624 | ||
619 | void cgit_print_pageheader(struct cgit_context *ctx) | 625 | void cgit_print_pageheader(struct cgit_context *ctx) |
620 | { | 626 | { |
621 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | 627 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |
622 | 628 | ||
623 | if (!cmd && ctx->repo) | 629 | if (!cmd && ctx->repo) |
624 | fallback_cmd = "summary"; | 630 | fallback_cmd = "summary"; |
625 | 631 | ||
626 | html("<table id='header'>\n"); | 632 | html("<table id='header'>\n"); |
627 | html("<tr>\n"); | 633 | html("<tr>\n"); |
628 | html("<td class='logo' rowspan='2'><a href='"); | 634 | html("<td class='logo' rowspan='2'><a href='"); |
629 | if (ctx->cfg.logo_link) | 635 | if (ctx->cfg.logo_link) |
630 | html_attr(ctx->cfg.logo_link); | 636 | html_attr(ctx->cfg.logo_link); |
631 | else | 637 | else |
632 | html_attr(cgit_rooturl()); | 638 | html_attr(cgit_rooturl()); |
633 | html("'><img src='"); | 639 | html("'><img src='"); |
634 | html_attr(ctx->cfg.logo); | 640 | html_attr(ctx->cfg.logo); |
635 | html("' alt='cgit logo'/></a></td>\n"); | 641 | html("' alt='cgit logo'/></a></td>\n"); |
636 | 642 | ||
637 | html("<td class='main'>"); | 643 | html("<td class='main'>"); |
638 | if (ctx->repo) { | 644 | if (ctx->repo) { |
639 | cgit_index_link("index", NULL, NULL, NULL, 0); | 645 | cgit_index_link("index", NULL, NULL, NULL, 0); |
640 | html(" : "); | 646 | html(" : "); |
641 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 647 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
642 | html("</td><td class='form'>"); | 648 | html("</td><td class='form'>"); |
643 | html("<form method='get' action=''>\n"); | 649 | html("<form method='get' action=''>\n"); |
644 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); | 650 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); |
645 | html("<select name='h' onchange='this.form.submit();'>\n"); | 651 | html("<select name='h' onchange='this.form.submit();'>\n"); |
646 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 652 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
647 | html("</select> "); | 653 | html("</select> "); |
648 | html("<input type='submit' name='' value='switch'/>"); | 654 | html("<input type='submit' name='' value='switch'/>"); |
649 | html("</form>"); | 655 | html("</form>"); |
650 | } else | 656 | } else |
651 | html_txt(ctx->cfg.root_title); | 657 | html_txt(ctx->cfg.root_title); |
652 | html("</td></tr>\n"); | 658 | html("</td></tr>\n"); |
653 | 659 | ||
654 | html("<tr><td class='sub'>"); | 660 | html("<tr><td class='sub'>"); |
655 | if (ctx->repo) { | 661 | if (ctx->repo) { |
656 | html_txt(ctx->repo->desc); | 662 | html_txt(ctx->repo->desc); |
657 | html("</td><td class='sub right'>"); | 663 | html("</td><td class='sub right'>"); |
658 | html_txt(ctx->repo->owner); | 664 | html_txt(ctx->repo->owner); |
659 | } else { | 665 | } else { |
660 | if (ctx->cfg.root_desc) | 666 | if (ctx->cfg.root_desc) |
661 | html_txt(ctx->cfg.root_desc); | 667 | html_txt(ctx->cfg.root_desc); |
662 | else if (ctx->cfg.index_info) | 668 | else if (ctx->cfg.index_info) |
663 | html_include(ctx->cfg.index_info); | 669 | html_include(ctx->cfg.index_info); |
664 | } | 670 | } |
665 | html("</td></tr></table>\n"); | 671 | html("</td></tr></table>\n"); |
666 | 672 | ||
667 | html("<table class='tabs'><tr><td>\n"); | 673 | html("<table class='tabs'><tr><td>\n"); |
668 | if (ctx->repo) { | 674 | if (ctx->repo) { |
669 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), | 675 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), |
670 | ctx->qry.head); | 676 | ctx->qry.head); |
671 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 677 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
672 | ctx->qry.sha1, NULL); | 678 | ctx->qry.sha1, NULL); |
673 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 679 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
674 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); | 680 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); |
675 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 681 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
676 | ctx->qry.sha1, NULL); | 682 | ctx->qry.sha1, NULL); |