about summary refs log tree commit diff
path: root/ui-shared.c
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2011-06-15 10:04:13 +0200
committerLars Hjemli <hjemli@gmail.com>2011-06-15 10:40:13 +0200
commit6857bec50a52340fa6b85d626f49d45dd331ed0e (patch)
treef746931d5173cab78d32ead3196186c97c5fd9b7 /ui-shared.c
parentMerge branch 'stable' (diff)
downloadcgit-pink-6857bec50a52340fa6b85d626f49d45dd331ed0e.tar.gz
cgit-pink-6857bec50a52340fa6b85d626f49d45dd331ed0e.zip
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 '')
-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)
 	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("<a ");
+	if (class)
+		htmlf("class='%s' ", class);
+	html("href='");
+	if (item) {
+		html_attr(fmt(item->util, rev));
+	} else if (ctx.repo->module_link) {
+		dir = strrchr(path, '/');
+		if (dir)
+			dir++;
+		else
+			dir = path;
+		html_attr(fmt(ctx.repo->module_link, dir, rev));
+	} else {
+		html("#");
+	}
+	html("'>");
+	html_txt(path);
+	html("</a>");
+	if (item && tail)
+		path[len - 1] = tail;
+}
+
 void cgit_print_date(time_t secs, const char *format, int local_time)
 {
 	char buf[64];
ar current cacheLars Hjemli 2006-12-13Remove implementation details from READMELars Hjemli 2006-12-13Small layout adjustments to summary and blob viewLars Hjemli 2006-12-13Add display of tree content w/ui-tree.cLars Hjemli 2006-12-12cache_lock: do xstrdup/free on lockfileLars Hjemli 2006-12-11Don't truncate valid cachefilesLars Hjemli 2006-12-11Move global variables + callback functions into shared.cLars Hjemli 2006-12-11Move functions for generic object output into ui-view.cLars Hjemli 2006-12-11Move log-functions into ui-log.cLars Hjemli 2006-12-11Move repo summary functions into ui-summary.cLars Hjemli 2006-12-11Move functions for repolist output into ui-repolist.cLars Hjemli 2006-12-11Move common output-functions into ui-shared.cLars Hjemli 2006-12-11Rename config.c to parsing.c + move cgit_parse_query from cgit.c to parsing.cLars Hjemli 2006-12-11Avoid infinite loops in caching layerLars Hjemli 2006-12-11Let 'make install' clear all cachefilesLars Hjemli 2006-12-11Fix cache algorithm loopholeLars Hjemli 2006-12-10Add version identifier in generated filesLars Hjemli 2006-12-10Add license file and copyright noticesLars Hjemli 2006-12-10Add caching infrastructureLars Hjemli