From 6857bec50a52340fa6b85d626f49d45dd331ed0e Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Wed, 15 Jun 2011 10:04:13 +0200 Subject: 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.', which will be used for linking to submodules at paths matching one such entry. Signed-off-by: Lars Hjemli --- ui-shared.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'ui-shared.c') 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) reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); } +struct string_list_item *lookup_path(struct string_list *list, + const char *path) +{ + struct string_list_item *item; + + while (path && path[0]) { + if ((item = string_list_lookup(list, path))) + return item; + if (!(path = strchr(path, '/'))) + break; + path++; + } + return NULL; +} + +void cgit_submodule_link(const char *class, char *path, const char *rev) +{ + struct string_list *list; + struct string_list_item *item; + char tail, *dir; + size_t len; + + tail = 0; + list = &ctx.repo->submodules; + item = lookup_path(list, path); + if (!item) { + len = strlen(path); + tail = path[len - 1]; + if (tail == '/') { + path[len - 1] = 0; + item = lookup_path(list, path); + } + } + html("module_link, dir, rev)); + } else { + html("#"); + } + html("'>"); + html_txt(path); + html(""); + if (item && tail) + path[len - 1] = tail; +} + void cgit_print_date(time_t secs, const char *format, int local_time) { char buf[64]; -- cgit v1.2.3-70-g09d2