author | Lars Hjemli <hjemli@gmail.com> | 2008-08-06 08:53:50 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-08-06 09:21:30 (UTC) |
commit | e5da4bca54574522b28f88cab0dc8ebad9e35a73 (patch) (unidiff) | |
tree | 08e02b9e0962a12040faab27e7841a74a800ddf2 /ui-shared.c | |
parent | 02a545e63454530c1639014d3239c14ced2022c6 (diff) | |
download | cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.zip cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.tar.gz cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.tar.bz2 |
Implement plain view
This implements a way to access plain blobs by path (similar to the
tree view) instead of by sha1.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index 197ee37..4408969 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -293,256 +293,258 @@ void cgit_refs_link(char *name, char *title, char *class, char *head, | |||
293 | } | 293 | } |
294 | 294 | ||
295 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 295 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
296 | char *rev, char *archivename) | 296 | char *rev, char *archivename) |
297 | { | 297 | { |
298 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 298 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
299 | } | 299 | } |
300 | 300 | ||
301 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 301 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
302 | char *new_rev, char *old_rev, char *path) | 302 | char *new_rev, char *old_rev, char *path) |
303 | { | 303 | { |
304 | char *delim; | 304 | char *delim; |
305 | 305 | ||
306 | delim = repolink(title, class, "diff", head, path); | 306 | delim = repolink(title, class, "diff", head, path); |
307 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 307 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
308 | html(delim); | 308 | html(delim); |
309 | html("id="); | 309 | html("id="); |
310 | html_attr(new_rev); | 310 | html_attr(new_rev); |
311 | delim = "&"; | 311 | delim = "&"; |
312 | } | 312 | } |
313 | if (old_rev) { | 313 | if (old_rev) { |
314 | html(delim); | 314 | html(delim); |
315 | html("id2="); | 315 | html("id2="); |
316 | html_attr(old_rev); | 316 | html_attr(old_rev); |
317 | } | 317 | } |
318 | html("'>"); | 318 | html("'>"); |
319 | html_txt(name); | 319 | html_txt(name); |
320 | html("</a>"); | 320 | html("</a>"); |
321 | } | 321 | } |
322 | 322 | ||
323 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 323 | void cgit_patch_link(char *name, char *title, char *class, char *head, |
324 | char *rev) | 324 | char *rev) |
325 | { | 325 | { |
326 | reporevlink("patch", name, title, class, head, rev, NULL); | 326 | reporevlink("patch", name, title, class, head, rev, NULL); |
327 | } | 327 | } |
328 | 328 | ||
329 | void cgit_object_link(struct object *obj) | 329 | void cgit_object_link(struct object *obj) |
330 | { | 330 | { |
331 | char *page, *arg, *url; | 331 | char *page, *arg, *url; |
332 | 332 | ||
333 | if (obj->type == OBJ_COMMIT) { | 333 | if (obj->type == OBJ_COMMIT) { |
334 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 334 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
335 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 335 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
336 | return; | 336 | return; |
337 | } else if (obj->type == OBJ_TREE) { | 337 | } else if (obj->type == OBJ_TREE) { |
338 | page = "tree"; | 338 | page = "tree"; |
339 | arg = "id"; | 339 | arg = "id"; |
340 | } else if (obj->type == OBJ_TAG) { | 340 | } else if (obj->type == OBJ_TAG) { |
341 | page = "tag"; | 341 | page = "tag"; |
342 | arg = "id"; | 342 | arg = "id"; |
343 | } else { | 343 | } else { |
344 | page = "blob"; | 344 | page = "blob"; |
345 | arg = "id"; | 345 | arg = "id"; |
346 | } | 346 | } |
347 | 347 | ||
348 | url = cgit_pageurl(ctx.qry.repo, page, | 348 | url = cgit_pageurl(ctx.qry.repo, page, |
349 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 349 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
350 | html_link_open(url, NULL, NULL); | 350 | html_link_open(url, NULL, NULL); |
351 | htmlf("%s %s", typename(obj->type), | 351 | htmlf("%s %s", typename(obj->type), |
352 | sha1_to_hex(obj->sha1)); | 352 | sha1_to_hex(obj->sha1)); |
353 | html_link_close(); | 353 | html_link_close(); |
354 | } | 354 | } |
355 | 355 | ||
356 | void cgit_print_date(time_t secs, char *format, int local_time) | 356 | void cgit_print_date(time_t secs, char *format, int local_time) |
357 | { | 357 | { |
358 | char buf[64]; | 358 | char buf[64]; |
359 | struct tm *time; | 359 | struct tm *time; |
360 | 360 | ||
361 | if (!secs) | 361 | if (!secs) |
362 | return; | 362 | return; |
363 | if(local_time) | 363 | if(local_time) |
364 | time = localtime(&secs); | 364 | time = localtime(&secs); |
365 | else | 365 | else |
366 | time = gmtime(&secs); | 366 | time = gmtime(&secs); |
367 | strftime(buf, sizeof(buf)-1, format, time); | 367 | strftime(buf, sizeof(buf)-1, format, time); |
368 | html_txt(buf); | 368 | html_txt(buf); |
369 | } | 369 | } |
370 | 370 | ||
371 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 371 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
372 | { | 372 | { |
373 | time_t now, secs; | 373 | time_t now, secs; |
374 | 374 | ||
375 | if (!t) | 375 | if (!t) |
376 | return; | 376 | return; |
377 | time(&now); | 377 | time(&now); |
378 | secs = now - t; | 378 | secs = now - t; |
379 | 379 | ||
380 | if (secs > max_relative && max_relative >= 0) { | 380 | if (secs > max_relative && max_relative >= 0) { |
381 | cgit_print_date(t, format, ctx.cfg.local_time); | 381 | cgit_print_date(t, format, ctx.cfg.local_time); |
382 | return; | 382 | return; |
383 | } | 383 | } |
384 | 384 | ||
385 | if (secs < TM_HOUR * 2) { | 385 | if (secs < TM_HOUR * 2) { |
386 | htmlf("<span class='age-mins'>%.0f min.</span>", | 386 | htmlf("<span class='age-mins'>%.0f min.</span>", |
387 | secs * 1.0 / TM_MIN); | 387 | secs * 1.0 / TM_MIN); |
388 | return; | 388 | return; |
389 | } | 389 | } |
390 | if (secs < TM_DAY * 2) { | 390 | if (secs < TM_DAY * 2) { |
391 | htmlf("<span class='age-hours'>%.0f hours</span>", | 391 | htmlf("<span class='age-hours'>%.0f hours</span>", |
392 | secs * 1.0 / TM_HOUR); | 392 | secs * 1.0 / TM_HOUR); |
393 | return; | 393 | return; |
394 | } | 394 | } |
395 | if (secs < TM_WEEK * 2) { | 395 | if (secs < TM_WEEK * 2) { |
396 | htmlf("<span class='age-days'>%.0f days</span>", | 396 | htmlf("<span class='age-days'>%.0f days</span>", |
397 | secs * 1.0 / TM_DAY); | 397 | secs * 1.0 / TM_DAY); |
398 | return; | 398 | return; |
399 | } | 399 | } |
400 | if (secs < TM_MONTH * 2) { | 400 | if (secs < TM_MONTH * 2) { |
401 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 401 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
402 | secs * 1.0 / TM_WEEK); | 402 | secs * 1.0 / TM_WEEK); |
403 | return; | 403 | return; |
404 | } | 404 | } |
405 | if (secs < TM_YEAR * 2) { | 405 | if (secs < TM_YEAR * 2) { |
406 | htmlf("<span class='age-months'>%.0f months</span>", | 406 | htmlf("<span class='age-months'>%.0f months</span>", |
407 | secs * 1.0 / TM_MONTH); | 407 | secs * 1.0 / TM_MONTH); |
408 | return; | 408 | return; |
409 | } | 409 | } |
410 | htmlf("<span class='age-years'>%.0f years</span>", | 410 | htmlf("<span class='age-years'>%.0f years</span>", |
411 | secs * 1.0 / TM_YEAR); | 411 | secs * 1.0 / TM_YEAR); |
412 | } | 412 | } |
413 | 413 | ||
414 | void cgit_print_http_headers(struct cgit_context *ctx) | 414 | void cgit_print_http_headers(struct cgit_context *ctx) |
415 | { | 415 | { |
416 | if (ctx->page.mimetype && ctx->page.charset) | 416 | if (ctx->page.mimetype && ctx->page.charset) |
417 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 417 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
418 | ctx->page.charset); | 418 | ctx->page.charset); |
419 | else if (ctx->page.mimetype) | 419 | else if (ctx->page.mimetype) |
420 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 420 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
421 | if (ctx->page.size) | ||
422 | htmlf("Content-Length: %ld\n", ctx->page.size); | ||
421 | if (ctx->page.filename) | 423 | if (ctx->page.filename) |
422 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 424 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
423 | ctx->page.filename); | 425 | ctx->page.filename); |
424 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 426 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
425 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 427 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
426 | html("\n"); | 428 | html("\n"); |
427 | } | 429 | } |
428 | 430 | ||
429 | void cgit_print_docstart(struct cgit_context *ctx) | 431 | void cgit_print_docstart(struct cgit_context *ctx) |
430 | { | 432 | { |
431 | html(cgit_doctype); | 433 | html(cgit_doctype); |
432 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 434 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
433 | html("<head>\n"); | 435 | html("<head>\n"); |
434 | html("<title>"); | 436 | html("<title>"); |
435 | html_txt(ctx->page.title); | 437 | html_txt(ctx->page.title); |
436 | html("</title>\n"); | 438 | html("</title>\n"); |
437 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 439 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
438 | if (ctx->cfg.robots && *ctx->cfg.robots) | 440 | if (ctx->cfg.robots && *ctx->cfg.robots) |
439 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 441 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
440 | html("<link rel='stylesheet' type='text/css' href='"); | 442 | html("<link rel='stylesheet' type='text/css' href='"); |
441 | html_attr(ctx->cfg.css); | 443 | html_attr(ctx->cfg.css); |
442 | html("'/>\n"); | 444 | html("'/>\n"); |
443 | if (ctx->cfg.favicon) { | 445 | if (ctx->cfg.favicon) { |
444 | html("<link rel='shortcut icon' href='"); | 446 | html("<link rel='shortcut icon' href='"); |
445 | html_attr(ctx->cfg.favicon); | 447 | html_attr(ctx->cfg.favicon); |
446 | html("'/>\n"); | 448 | html("'/>\n"); |
447 | } | 449 | } |
448 | html("</head>\n"); | 450 | html("</head>\n"); |
449 | html("<body>\n"); | 451 | html("<body>\n"); |
450 | } | 452 | } |
451 | 453 | ||
452 | void cgit_print_docend() | 454 | void cgit_print_docend() |
453 | { | 455 | { |
454 | html("</div>"); | 456 | html("</div>"); |
455 | if (ctx.cfg.footer) | 457 | if (ctx.cfg.footer) |
456 | html_include(ctx.cfg.footer); | 458 | html_include(ctx.cfg.footer); |
457 | else { | 459 | else { |
458 | html("<div class='footer'>generated "); | 460 | html("<div class='footer'>generated "); |
459 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 461 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
460 | htmlf(" by cgit %s", cgit_version); | 462 | htmlf(" by cgit %s", cgit_version); |
461 | html("</div>\n"); | 463 | html("</div>\n"); |
462 | } | 464 | } |
463 | html("</body>\n</html>\n"); | 465 | html("</body>\n</html>\n"); |
464 | } | 466 | } |
465 | 467 | ||
466 | int print_branch_option(const char *refname, const unsigned char *sha1, | 468 | int print_branch_option(const char *refname, const unsigned char *sha1, |
467 | int flags, void *cb_data) | 469 | int flags, void *cb_data) |
468 | { | 470 | { |
469 | char *name = (char *)refname; | 471 | char *name = (char *)refname; |
470 | html_option(name, name, ctx.qry.head); | 472 | html_option(name, name, ctx.qry.head); |
471 | return 0; | 473 | return 0; |
472 | } | 474 | } |
473 | 475 | ||
474 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 476 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
475 | int flags, void *cb_data) | 477 | int flags, void *cb_data) |
476 | { | 478 | { |
477 | struct tag *tag; | 479 | struct tag *tag; |
478 | struct taginfo *info; | 480 | struct taginfo *info; |
479 | struct object *obj; | 481 | struct object *obj; |
480 | char buf[256], *url; | 482 | char buf[256], *url; |
481 | unsigned char fileid[20]; | 483 | unsigned char fileid[20]; |
482 | int *header = (int *)cb_data; | 484 | int *header = (int *)cb_data; |
483 | 485 | ||
484 | if (prefixcmp(refname, "refs/archives")) | 486 | if (prefixcmp(refname, "refs/archives")) |
485 | return 0; | 487 | return 0; |
486 | strncpy(buf, refname+14, sizeof(buf)); | 488 | strncpy(buf, refname+14, sizeof(buf)); |
487 | obj = parse_object(sha1); | 489 | obj = parse_object(sha1); |
488 | if (!obj) | 490 | if (!obj) |
489 | return 1; | 491 | return 1; |
490 | if (obj->type == OBJ_TAG) { | 492 | if (obj->type == OBJ_TAG) { |
491 | tag = lookup_tag(sha1); | 493 | tag = lookup_tag(sha1); |
492 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 494 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
493 | return 0; | 495 | return 0; |
494 | hashcpy(fileid, tag->tagged->sha1); | 496 | hashcpy(fileid, tag->tagged->sha1); |
495 | } else if (obj->type != OBJ_BLOB) { | 497 | } else if (obj->type != OBJ_BLOB) { |
496 | return 0; | 498 | return 0; |
497 | } else { | 499 | } else { |
498 | hashcpy(fileid, sha1); | 500 | hashcpy(fileid, sha1); |
499 | } | 501 | } |
500 | if (!*header) { | 502 | if (!*header) { |
501 | html("<h1>download</h1>\n"); | 503 | html("<h1>download</h1>\n"); |
502 | *header = 1; | 504 | *header = 1; |
503 | } | 505 | } |
504 | url = cgit_pageurl(ctx.qry.repo, "blob", | 506 | url = cgit_pageurl(ctx.qry.repo, "blob", |
505 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 507 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
506 | buf)); | 508 | buf)); |
507 | html_link_open(url, NULL, "menu"); | 509 | html_link_open(url, NULL, "menu"); |
508 | html_txt(strlpart(buf, 20)); | 510 | html_txt(strlpart(buf, 20)); |
509 | html_link_close(); | 511 | html_link_close(); |
510 | return 0; | 512 | return 0; |
511 | } | 513 | } |
512 | 514 | ||
513 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 515 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
514 | { | 516 | { |
515 | char *url; | 517 | char *url; |
516 | 518 | ||
517 | if (!ctx.cfg.virtual_root) { | 519 | if (!ctx.cfg.virtual_root) { |
518 | url = fmt("%s/%s", ctx.qry.repo, page); | 520 | url = fmt("%s/%s", ctx.qry.repo, page); |
519 | if (ctx.qry.path) | 521 | if (ctx.qry.path) |
520 | url = fmt("%s/%s", url, ctx.qry.path); | 522 | url = fmt("%s/%s", url, ctx.qry.path); |
521 | html_hidden("url", url); | 523 | html_hidden("url", url); |
522 | } | 524 | } |
523 | 525 | ||
524 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 526 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
525 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 527 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
526 | html_hidden("h", ctx.qry.head); | 528 | html_hidden("h", ctx.qry.head); |
527 | 529 | ||
528 | if (ctx.qry.sha1) | 530 | if (ctx.qry.sha1) |
529 | html_hidden("id", ctx.qry.sha1); | 531 | html_hidden("id", ctx.qry.sha1); |
530 | if (ctx.qry.sha2) | 532 | if (ctx.qry.sha2) |
531 | html_hidden("id2", ctx.qry.sha2); | 533 | html_hidden("id2", ctx.qry.sha2); |
532 | 534 | ||
533 | if (incl_search) { | 535 | if (incl_search) { |
534 | if (ctx.qry.grep) | 536 | if (ctx.qry.grep) |
535 | html_hidden("qt", ctx.qry.grep); | 537 | html_hidden("qt", ctx.qry.grep); |
536 | if (ctx.qry.search) | 538 | if (ctx.qry.search) |
537 | html_hidden("q", ctx.qry.search); | 539 | html_hidden("q", ctx.qry.search); |
538 | } | 540 | } |
539 | } | 541 | } |
540 | 542 | ||
541 | char *hc(struct cgit_cmd *cmd, const char *page) | 543 | char *hc(struct cgit_cmd *cmd, const char *page) |
542 | { | 544 | { |
543 | return (strcmp(cmd->name, page) ? NULL : "active"); | 545 | return (strcmp(cmd->name, page) ? NULL : "active"); |
544 | } | 546 | } |
545 | 547 | ||
546 | void cgit_print_pageheader(struct cgit_context *ctx) | 548 | void cgit_print_pageheader(struct cgit_context *ctx) |
547 | { | 549 | { |
548 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | 550 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |