aboutsummaryrefslogtreecommitdiffstats
path: root/ui-shared.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2012-03-19 05:59:36 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2012-03-19 05:59:36 (JST)
commit2b9fab8d30420d935745c4d84ea22412ab2485e5 (patch)
tree664ebc3d061fd7e89393af67bfbc406f3b600be0 /ui-shared.c
parent08352c7a02f057f6cbaf817ca7e53c53be590a62 (diff)
parent3fbaf097153b239b092d11a178ace96671f9f3ec (diff)
downloadcgit-2b9fab8d30420d935745c4d84ea22412ab2485e5.zip
cgit-2b9fab8d30420d935745c4d84ea22412ab2485e5.tar.gz
Merge branch 'lh/module-links'
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c56
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
512struct 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
527void 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
512void cgit_print_date(time_t secs, const char *format, int local_time) 568void cgit_print_date(time_t secs, const char *format, int local_time)
513{ 569{
514 char buf[64]; 570 char buf[64];