summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-01-11 23:46:17 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-01-11 23:46:17 (UTC)
commit5cd2bf7e7f3f3daf6107cd3a269bad78e342de70 (patch) (unidiff)
tree7ce9368e94b39114e772c279f741bd8106f611d2
parent2c2047ff67a1e0053f95776e5079e432f69cea54 (diff)
downloadcgit-5cd2bf7e7f3f3daf6107cd3a269bad78e342de70.zip
cgit-5cd2bf7e7f3f3daf6107cd3a269bad78e342de70.tar.gz
cgit-5cd2bf7e7f3f3daf6107cd3a269bad78e342de70.tar.bz2
WIP: add paths/backlinks to tree/blobview
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h3
-rw-r--r--shared.c3
-rw-r--r--ui-tree.c12
4 files changed, 15 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index a3a04d9..9535abc 100644
--- a/cgit.c
+++ b/cgit.c
@@ -51,17 +51,17 @@ static void cgit_print_repo_page(struct cacheitem *item)
51 show_search = 1; 51 show_search = 1;
52 cgit_print_docstart(title, item); 52 cgit_print_docstart(title, item);
53 cgit_print_pageheader(title, show_search); 53 cgit_print_pageheader(title, show_search);
54 if (!cgit_query_page) { 54 if (!cgit_query_page) {
55 cgit_print_summary(); 55 cgit_print_summary();
56 } else if (!strcmp(cgit_query_page, "log")) { 56 } else if (!strcmp(cgit_query_page, "log")) {
57 cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search); 57 cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search);
58 } else if (!strcmp(cgit_query_page, "tree")) { 58 } else if (!strcmp(cgit_query_page, "tree")) {
59 cgit_print_tree(cgit_query_sha1); 59 cgit_print_tree(cgit_query_sha1, cgit_query_path);
60 } else if (!strcmp(cgit_query_page, "commit")) { 60 } else if (!strcmp(cgit_query_page, "commit")) {
61 cgit_print_commit(cgit_query_sha1); 61 cgit_print_commit(cgit_query_sha1);
62 } else if (!strcmp(cgit_query_page, "view")) { 62 } else if (!strcmp(cgit_query_page, "view")) {
63 cgit_print_view(cgit_query_sha1); 63 cgit_print_view(cgit_query_sha1);
64 } else if (!strcmp(cgit_query_page, "diff")) { 64 } else if (!strcmp(cgit_query_page, "diff")) {
65 cgit_print_diff(cgit_query_sha1, cgit_query_sha2); 65 cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
66 } 66 }
67 cgit_print_docend(); 67 cgit_print_docend();
diff --git a/cgit.h b/cgit.h
index 3601e49..5e19b11 100644
--- a/cgit.h
+++ b/cgit.h
@@ -54,16 +54,17 @@ extern int cgit_query_has_sha1;
54 54
55extern char *cgit_querystring; 55extern char *cgit_querystring;
56extern char *cgit_query_repo; 56extern char *cgit_query_repo;
57extern char *cgit_query_page; 57extern char *cgit_query_page;
58extern char *cgit_query_search; 58extern char *cgit_query_search;
59extern char *cgit_query_head; 59extern char *cgit_query_head;
60extern char *cgit_query_sha1; 60extern char *cgit_query_sha1;
61extern char *cgit_query_sha2; 61extern char *cgit_query_sha2;
62extern char *cgit_query_path;
62extern int cgit_query_ofs; 63extern int cgit_query_ofs;
63 64
64extern int htmlfd; 65extern int htmlfd;
65 66
66extern void cgit_global_config_cb(const char *name, const char *value); 67extern void cgit_global_config_cb(const char *name, const char *value);
67extern void cgit_repo_config_cb(const char *name, const char *value); 68extern void cgit_repo_config_cb(const char *name, const char *value);
68extern void cgit_querystring_cb(const char *name, const char *value); 69extern void cgit_querystring_cb(const char *name, const char *value);
69 70
@@ -103,13 +104,13 @@ extern void cgit_print_date(unsigned long secs);
103extern void cgit_print_docstart(char *title, struct cacheitem *item); 104extern void cgit_print_docstart(char *title, struct cacheitem *item);
104extern void cgit_print_docend(); 105extern void cgit_print_docend();
105extern void cgit_print_pageheader(char *title, int show_search); 106extern void cgit_print_pageheader(char *title, int show_search);
106 107
107extern void cgit_print_repolist(struct cacheitem *item); 108extern void cgit_print_repolist(struct cacheitem *item);
108extern void cgit_print_summary(); 109extern void cgit_print_summary();
109extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); 110extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
110extern void cgit_print_view(const char *hex); 111extern void cgit_print_view(const char *hex);
111extern void cgit_print_tree(const char *hex); 112extern void cgit_print_tree(const char *hex, char *path);
112extern void cgit_print_commit(const char *hex); 113extern void cgit_print_commit(const char *hex);
113extern void cgit_print_diff(const char *old_hex, const char *new_hex); 114extern void cgit_print_diff(const char *old_hex, const char *new_hex);
114 115
115#endif /* CGIT_H */ 116#endif /* CGIT_H */
diff --git a/shared.c b/shared.c
index e4595fa..dd711a8 100644
--- a/shared.c
+++ b/shared.c
@@ -34,16 +34,17 @@ int cgit_query_has_sha1 = 0;
34 34
35char *cgit_querystring = NULL; 35char *cgit_querystring = NULL;
36char *cgit_query_repo = NULL; 36char *cgit_query_repo = NULL;
37char *cgit_query_page = NULL; 37char *cgit_query_page = NULL;
38char *cgit_query_head = NULL; 38char *cgit_query_head = NULL;
39char *cgit_query_search = NULL; 39char *cgit_query_search = NULL;
40char *cgit_query_sha1 = NULL; 40char *cgit_query_sha1 = NULL;
41char *cgit_query_sha2 = NULL; 41char *cgit_query_sha2 = NULL;
42char *cgit_query_path = NULL;
42int cgit_query_ofs = 0; 43int cgit_query_ofs = 0;
43 44
44int htmlfd = 0; 45int htmlfd = 0;
45 46
46void cgit_global_config_cb(const char *name, const char *value) 47void cgit_global_config_cb(const char *name, const char *value)
47{ 48{
48 if (!strcmp(name, "root")) 49 if (!strcmp(name, "root"))
49 cgit_root = xstrdup(value); 50 cgit_root = xstrdup(value);
@@ -95,16 +96,18 @@ void cgit_querystring_cb(const char *name, const char *value)
95 } else if (!strcmp(name, "id")) { 96 } else if (!strcmp(name, "id")) {
96 cgit_query_sha1 = xstrdup(value); 97 cgit_query_sha1 = xstrdup(value);
97 cgit_query_has_sha1 = 1; 98 cgit_query_has_sha1 = 1;
98 } else if (!strcmp(name, "id2")) { 99 } else if (!strcmp(name, "id2")) {
99 cgit_query_sha2 = xstrdup(value); 100 cgit_query_sha2 = xstrdup(value);
100 cgit_query_has_sha1 = 1; 101 cgit_query_has_sha1 = 1;
101 } else if (!strcmp(name, "ofs")) { 102 } else if (!strcmp(name, "ofs")) {
102 cgit_query_ofs = atoi(value); 103 cgit_query_ofs = atoi(value);
104 } else if (!strcmp(name, "path")) {
105 cgit_query_path = xstrdup(value);
103 } 106 }
104} 107}
105 108
106void *cgit_free_commitinfo(struct commitinfo *info) 109void *cgit_free_commitinfo(struct commitinfo *info)
107{ 110{
108 free(info->author); 111 free(info->author);
109 free(info->author_email); 112 free(info->author_email);
110 free(info->committer); 113 free(info->committer);
diff --git a/ui-tree.c b/ui-tree.c
index 54dcdbe..ed9f05e 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -24,49 +24,55 @@ static int print_entry(const unsigned char *sha1, const char *base,
24 } 24 }
25 name = xstrdup(pathname); 25 name = xstrdup(pathname);
26 html("<tr><td class='filemode'>"); 26 html("<tr><td class='filemode'>");
27 html_filemode(mode); 27 html_filemode(mode);
28 html("</td><td>"); 28 html("</td><td>");
29 if (S_ISDIR(mode)) { 29 if (S_ISDIR(mode)) {
30 html("<div class='ls-dir'><a href='"); 30 html("<div class='ls-dir'><a href='");
31 html_attr(cgit_pageurl(cgit_query_repo, "tree", 31 html_attr(cgit_pageurl(cgit_query_repo, "tree",
32 fmt("id=%s", sha1_to_hex(sha1)))); 32 fmt("id=%s&path=%s%s/",
33 sha1_to_hex(sha1),
34 cgit_query_path ? cgit_query_path : "",
35 pathname)));
33 } else { 36 } else {
34 html("<div class='ls-blob'><a href='"); 37 html("<div class='ls-blob'><a href='");
35 html_attr(cgit_pageurl(cgit_query_repo, "view", 38 html_attr(cgit_pageurl(cgit_query_repo, "view",
36 fmt("id=%s", sha1_to_hex(sha1)))); 39 fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
40 cgit_query_path ? cgit_query_path : "",
41 pathname)));
37 } 42 }
38 html("'>"); 43 html("'>");
39 html_txt(name); 44 html_txt(name);
40 if (S_ISDIR(mode)) 45 if (S_ISDIR(mode))
41 html("/"); 46 html("/");
42 html("</a></div></td>"); 47 html("</a></div></td>");
43 htmlf("<td class='filesize'>%li</td>", size); 48 htmlf("<td class='filesize'>%li</td>", size);
44 html("</tr>\n"); 49 html("</tr>\n");
45 free(name); 50 free(name);
46 return 0; 51 return 0;
47} 52}
48 53
49void cgit_print_tree(const char *hex) 54void cgit_print_tree(const char *hex, char *path)
50{ 55{
51 struct tree *tree; 56 struct tree *tree;
52 unsigned char sha1[20]; 57 unsigned char sha1[20];
53 58
54 if (get_sha1_hex(hex, sha1)) { 59 if (get_sha1_hex(hex, sha1)) {
55 cgit_print_error(fmt("Invalid object id: %s", hex)); 60 cgit_print_error(fmt("Invalid object id: %s", hex));
56 return; 61 return;
57 } 62 }
58 tree = parse_tree_indirect(sha1); 63 tree = parse_tree_indirect(sha1);
59 if (!tree) { 64 if (!tree) {
60 cgit_print_error(fmt("Not a tree object: %s", hex)); 65 cgit_print_error(fmt("Not a tree object: %s", hex));
61 return; 66 return;
62 } 67 }
63 68
64 html("<h2>Tree content</h2>\n"); 69 html("<h2>Tree content</h2>\n");
70 html_txt(path);
65 html("<table class='list'>\n"); 71 html("<table class='list'>\n");
66 html("<tr>"); 72 html("<tr>");
67 html("<th class='left'>Mode</th>"); 73 html("<th class='left'>Mode</th>");
68 html("<th class='left'>Name</th>"); 74 html("<th class='left'>Name</th>");
69 html("<th class='right'>Size</th>"); 75 html("<th class='right'>Size</th>");
70 html("</tr>\n"); 76 html("</tr>\n");
71 read_tree_recursive(tree, "", 0, 1, NULL, print_entry); 77 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
72 html("</table>\n"); 78 html("</table>\n");