cgit

commit 5cd2bf7e7f3f3daf6107cd3a269bad78e342de70

Author: Lars Hjemli <hjemli@gmail.com>

WIP: add paths/backlinks to tree/blobview

 cgit.c | 2 +-
 cgit.h | 3 ++-
 shared.c | 3 +++
 ui-tree.c | 12 +++++++++---


diff --git a/cgit.c b/cgit.c
index a3a04d9106515a318618268f636e0c7fe2a0a57f..9535abc4128e47df2a57a19e3fbff97d650a3c0a 100644
--- a/cgit.c
+++ b/cgit.c
@@ -56,7 +56,7 @@ 		cgit_print_summary();
 	} else if (!strcmp(cgit_query_page, "log")) {
 		cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search);
 	} else if (!strcmp(cgit_query_page, "tree")) {
-		cgit_print_tree(cgit_query_sha1);
+		cgit_print_tree(cgit_query_sha1, cgit_query_path);
 	} else if (!strcmp(cgit_query_page, "commit")) {
 		cgit_print_commit(cgit_query_sha1);
 	} else if (!strcmp(cgit_query_page, "view")) {




diff --git a/cgit.h b/cgit.h
index 3601e49a831b52c418b7c1c307742b26e28f7734..5e19b117b3fd5c42da99d3e938f37fd53db2fc98 100644
--- a/cgit.h
+++ b/cgit.h
@@ -59,6 +59,7 @@ extern char *cgit_query_search;
 extern char *cgit_query_head;
 extern char *cgit_query_sha1;
 extern char *cgit_query_sha2;
+extern char *cgit_query_path;
 extern int   cgit_query_ofs;
 
 extern int htmlfd;
@@ -108,7 +109,7 @@ extern void cgit_print_repolist(struct cacheitem *item);
 extern void cgit_print_summary();
 extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
 extern void cgit_print_view(const char *hex);
-extern void cgit_print_tree(const char *hex);
+extern void cgit_print_tree(const char *hex, char *path);
 extern void cgit_print_commit(const char *hex);
 extern void cgit_print_diff(const char *old_hex, const char *new_hex);
 




diff --git a/shared.c b/shared.c
index e4595fabe0cd2f1650fa1566adfb67c1568b60e3..dd711a86563c6452a75d4d57307f05533a4a63cf 100644
--- a/shared.c
+++ b/shared.c
@@ -39,6 +39,7 @@ char *cgit_query_head   = NULL;
 char *cgit_query_search = NULL;
 char *cgit_query_sha1   = NULL;
 char *cgit_query_sha2   = NULL;
+char *cgit_query_path   = NULL;
 int   cgit_query_ofs    = 0;
 
 int htmlfd = 0;
@@ -100,6 +101,8 @@ 		cgit_query_sha2 = xstrdup(value);
 		cgit_query_has_sha1 = 1;
 	} else if (!strcmp(name, "ofs")) {
 		cgit_query_ofs = atoi(value);
+	} else if (!strcmp(name, "path")) {
+		cgit_query_path = xstrdup(value);
 	}
 }
 




diff --git a/ui-tree.c b/ui-tree.c
index 54dcdbe2b1124be027cfe027bacc0fd2ab0bdead..ed9f05ea9cddf12df55228be316cd8d0b02510d7 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -29,11 +29,16 @@ 	html("");
 	if (S_ISDIR(mode)) {
 		html("<div class='ls-dir'><a href='");
 		html_attr(cgit_pageurl(cgit_query_repo, "tree", 
-				       fmt("id=%s", sha1_to_hex(sha1))));
+				       fmt("id=%s&path=%s%s/", 
+					   sha1_to_hex(sha1),
+					   cgit_query_path ? cgit_query_path : "",
+					   pathname)));
 	} else {
 		html("<div class='ls-blob'><a href='");
 		html_attr(cgit_pageurl(cgit_query_repo, "view",
-				      fmt("id=%s", sha1_to_hex(sha1))));
+				      fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
+					  cgit_query_path ? cgit_query_path : "",
+					  pathname)));
 	}
 	html("'>");
 	html_txt(name);
@@ -46,7 +51,7 @@ 	free(name);
 	return 0;
 }
 
-void cgit_print_tree(const char *hex)
+void cgit_print_tree(const char *hex, char *path)
 {
 	struct tree *tree;
 	unsigned char sha1[20];
@@ -62,6 +67,7 @@ 		return;
 	}
 
 	html("<h2>Tree content</h2>\n");
+	html_txt(path);
 	html("<table class='list'>\n");
 	html("<tr>");
 	html("<th class='left'>Mode</th>");