diff options
Diffstat (limited to 'ui-shared.c')
| -rw-r--r-- | ui-shared.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index d7d75bf..43166af 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
| @@ -509,6 +509,62 @@ void cgit_object_link(struct object *obj) | |||
| 509 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 509 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | struct string_list_item *lookup_path(struct string_list *list, | ||
| 513 | const char *path) | ||
| 514 | { | ||
| 515 | struct string_list_item *item; | ||
| 516 | |||
| 517 | while (path && path[0]) { | ||
| 518 | if ((item = string_list_lookup(list, path))) | ||
| 519 | return item; | ||
| 520 | if (!(path = strchr(path, '/'))) | ||
| 521 | break; | ||
| 522 | path++; | ||
| 523 | } | ||
| 524 | return NULL; | ||
| 525 | } | ||
| 526 | |||
| 527 | void cgit_submodule_link(const char *class, char *path, const char *rev) | ||
| 528 | { | ||
| 529 | struct string_list *list; | ||
| 530 | struct string_list_item *item; | ||
| 531 | char tail, *dir; | ||
| 532 | size_t len; | ||
| 533 | |||
| 534 | tail = 0; | ||
| 535 | list = &ctx.repo->submodules; | ||
| 536 | item = lookup_path(list, path); | ||
| 537 | if (!item) { | ||
| 538 | len = strlen(path); | ||
| 539 | tail = path[len - 1]; | ||
| 540 | if (tail == '/') { | ||
| 541 | path[len - 1] = 0; | ||
| 542 | item = lookup_path(list, path); | ||
| 543 | } | ||
| 544 | } | ||
| 545 | html("<a "); | ||
| 546 | if (class) | ||
| 547 | htmlf("class='%s' ", class); | ||
| 548 | html("href='"); | ||
| 549 | if (item) { | ||
| 550 | html_attr(fmt(item->util, rev)); | ||
| 551 | } else if (ctx.repo->module_link) { | ||
| 552 | dir = strrchr(path, '/'); | ||
| 553 | if (dir) | ||
| 554 | dir++; | ||
| 555 | else | ||
| 556 | dir = path; | ||
| 557 | html_attr(fmt(ctx.repo->module_link, dir, rev)); | ||
| 558 | } else { | ||
| 559 | html("#"); | ||
| 560 | } | ||
| 561 | html("'>"); | ||
| 562 | html_txt(path); | ||
| 563 | html("</a>"); | ||
| 564 | if (item && tail) | ||
| 565 | path[len - 1] = tail; | ||
| 566 | } | ||
| 567 | |||
| 512 | void cgit_print_date(time_t secs, const char *format, int local_time) | 568 | void cgit_print_date(time_t secs, const char *format, int local_time) |
| 513 | { | 569 | { |
| 514 | char buf[64]; | 570 | char buf[64]; |
