aboutsummaryrefslogtreecommitdiffstats
path: root/ui-shared.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2011-06-15 17:04:13 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2011-06-15 17:40:13 (JST)
commit6857bec50a52340fa6b85d626f49d45dd331ed0e (patch)
treef746931d5173cab78d32ead3196186c97c5fd9b7 /ui-shared.c
parent8729d251a900b2e6e22cc4c93a2193fd8a2b9acf (diff)
downloadcgit-6857bec50a52340fa6b85d626f49d45dd331ed0e.zip
cgit-6857bec50a52340fa6b85d626f49d45dd331ed0e.tar.gz
ui-tree.c: add support for path-selected submodule links
The current 'repo.module-link' option is sufficient when all gitlinks in a repository can be converted to commit links in a uniform way, but not when different submodules/paths needs different settings. This patch adds support for 'repo.module-link.<path>', which will be used for linking to submodules at paths matching one such entry. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
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 5aa9119..b736fca 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -503,6 +503,62 @@ void cgit_object_link(struct object *obj)
503 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 503 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
504} 504}
505 505
506struct string_list_item *lookup_path(struct string_list *list,
507 const char *path)
508{
509 struct string_list_item *item;
510
511 while (path && path[0]) {
512 if ((item = string_list_lookup(list, path)))
513 return item;
514 if (!(path = strchr(path, '/')))
515 break;
516 path++;
517 }
518 return NULL;
519}
520
521void cgit_submodule_link(const char *class, char *path, const char *rev)
522{
523 struct string_list *list;
524 struct string_list_item *item;
525 char tail, *dir;
526 size_t len;
527
528 tail = 0;
529 list = &ctx.repo->submodules;
530 item = lookup_path(list, path);
531 if (!item) {
532 len = strlen(path);
533 tail = path[len - 1];
534 if (tail == '/') {
535 path[len - 1] = 0;
536 item = lookup_path(list, path);
537 }
538 }
539 html("<a ");
540 if (class)
541 htmlf("class='%s' ", class);
542 html("href='");
543 if (item) {
544 html_attr(fmt(item->util, rev));
545 } else if (ctx.repo->module_link) {
546 dir = strrchr(path, '/');
547 if (dir)
548 dir++;
549 else
550 dir = path;
551 html_attr(fmt(ctx.repo->module_link, dir, rev));
552 } else {
553 html("#");
554 }
555 html("'>");
556 html_txt(path);
557 html("</a>");
558 if (item && tail)
559 path[len - 1] = tail;
560}
561
506void cgit_print_date(time_t secs, const char *format, int local_time) 562void cgit_print_date(time_t secs, const char *format, int local_time)
507{ 563{
508 char buf[64]; 564 char buf[64];