|
diff --git a/ui-tree.c b/ui-tree.c index c138877..7cae85a 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -25,25 +25,25 @@ static void print_object(const unsigned char *sha1, char *path) |
25 | sha1_to_hex(sha1))); |
25 | sha1_to_hex(sha1))); |
26 | return; |
26 | return; |
27 | } |
27 | } |
28 | |
28 | |
29 | buf = read_sha1_file(sha1, &type, &size); |
29 | buf = read_sha1_file(sha1, &type, &size); |
30 | if (!buf) { |
30 | if (!buf) { |
31 | cgit_print_error(fmt("Error reading object %s", |
31 | cgit_print_error(fmt("Error reading object %s", |
32 | sha1_to_hex(sha1))); |
32 | sha1_to_hex(sha1))); |
33 | return; |
33 | return; |
34 | } |
34 | } |
35 | |
35 | |
36 | html(" blob: <a href='"); |
36 | html(" blob: <a href='"); |
37 | html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); |
37 | html_attr(cgit_pageurl(ctx.qry.repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); |
38 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
38 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
39 | |
39 | |
40 | html("<table summary='blob content' class='blob'>\n"); |
40 | html("<table summary='blob content' class='blob'>\n"); |
41 | idx = 0; |
41 | idx = 0; |
42 | start = 0; |
42 | start = 0; |
43 | lineno = 0; |
43 | lineno = 0; |
44 | while(idx < size) { |
44 | while(idx < size) { |
45 | if (buf[idx] == '\n') { |
45 | if (buf[idx] == '\n') { |
46 | buf[idx] = '\0'; |
46 | buf[idx] = '\0'; |
47 | htmlf(linefmt, ++lineno); |
47 | htmlf(linefmt, ++lineno); |
48 | html_txt(buf + start); |
48 | html_txt(buf + start); |
49 | html("</td></tr>\n"); |
49 | html("</td></tr>\n"); |
@@ -58,57 +58,57 @@ static void print_object(const unsigned char *sha1, char *path) |
58 | } |
58 | } |
59 | |
59 | |
60 | |
60 | |
61 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
61 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
62 | const char *pathname, unsigned int mode, int stage) |
62 | const char *pathname, unsigned int mode, int stage) |
63 | { |
63 | { |
64 | char *name; |
64 | char *name; |
65 | char *fullpath; |
65 | char *fullpath; |
66 | enum object_type type; |
66 | enum object_type type; |
67 | unsigned long size = 0; |
67 | unsigned long size = 0; |
68 | |
68 | |
69 | name = xstrdup(pathname); |
69 | name = xstrdup(pathname); |
70 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", |
70 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
71 | cgit_query_path ? "/" : "", name); |
71 | ctx.qry.path ? "/" : "", name); |
72 | |
72 | |
73 | type = sha1_object_info(sha1, &size); |
73 | type = sha1_object_info(sha1, &size); |
74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
75 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
75 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
76 | name, |
76 | name, |
77 | sha1_to_hex(sha1)); |
77 | sha1_to_hex(sha1)); |
78 | return 0; |
78 | return 0; |
79 | } |
79 | } |
80 | |
80 | |
81 | html("<tr><td class='ls-mode'>"); |
81 | html("<tr><td class='ls-mode'>"); |
82 | html_filemode(mode); |
82 | html_filemode(mode); |
83 | html("</td><td>"); |
83 | html("</td><td>"); |
84 | if (S_ISGITLINK(mode)) { |
84 | if (S_ISGITLINK(mode)) { |
85 | htmlf("<a class='ls-mod' href='"); |
85 | htmlf("<a class='ls-mod' href='"); |
86 | html_attr(fmt(cgit_repo->module_link, |
86 | html_attr(fmt(cgit_repo->module_link, |
87 | name, |
87 | name, |
88 | sha1_to_hex(sha1))); |
88 | sha1_to_hex(sha1))); |
89 | html("'>"); |
89 | html("'>"); |
90 | html_txt(name); |
90 | html_txt(name); |
91 | html("</a>"); |
91 | html("</a>"); |
92 | } else if (S_ISDIR(mode)) { |
92 | } else if (S_ISDIR(mode)) { |
93 | cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, |
93 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
94 | curr_rev, fullpath); |
94 | curr_rev, fullpath); |
95 | } else { |
95 | } else { |
96 | cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, |
96 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
97 | curr_rev, fullpath); |
97 | curr_rev, fullpath); |
98 | } |
98 | } |
99 | htmlf("</td><td class='ls-size'>%li</td>", size); |
99 | htmlf("</td><td class='ls-size'>%li</td>", size); |
100 | |
100 | |
101 | html("<td>"); |
101 | html("<td>"); |
102 | cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, |
102 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
103 | fullpath, 0, NULL, NULL); |
103 | fullpath, 0, NULL, NULL); |
104 | html("</td></tr>\n"); |
104 | html("</td></tr>\n"); |
105 | free(name); |
105 | free(name); |
106 | return 0; |
106 | return 0; |
107 | } |
107 | } |
108 | |
108 | |
109 | static void ls_head() |
109 | static void ls_head() |
110 | { |
110 | { |
111 | html("<table summary='tree listing' class='list'>\n"); |
111 | html("<table summary='tree listing' class='list'>\n"); |
112 | html("<tr class='nohover'>"); |
112 | html("<tr class='nohover'>"); |
113 | html("<th class='left'>Mode</th>"); |
113 | html("<th class='left'>Mode</th>"); |
114 | html("<th class='left'>Name</th>"); |
114 | html("<th class='left'>Name</th>"); |
@@ -144,28 +144,28 @@ static void ls_tree(const unsigned char *sha1, char *path) |
144 | |
144 | |
145 | |
145 | |
146 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
146 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
147 | const char *pathname, unsigned mode, int stage) |
147 | const char *pathname, unsigned mode, int stage) |
148 | { |
148 | { |
149 | static int state; |
149 | static int state; |
150 | static char buffer[PATH_MAX]; |
150 | static char buffer[PATH_MAX]; |
151 | char *url; |
151 | char *url; |
152 | |
152 | |
153 | if (state == 0) { |
153 | if (state == 0) { |
154 | memcpy(buffer, base, baselen); |
154 | memcpy(buffer, base, baselen); |
155 | strcpy(buffer+baselen, pathname); |
155 | strcpy(buffer+baselen, pathname); |
156 | url = cgit_pageurl(cgit_query_repo, "tree", |
156 | url = cgit_pageurl(ctx.qry.repo, "tree", |
157 | fmt("h=%s&path=%s", curr_rev, buffer)); |
157 | fmt("h=%s&path=%s", curr_rev, buffer)); |
158 | html("/"); |
158 | html("/"); |
159 | cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, |
159 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, |
160 | curr_rev, buffer); |
160 | curr_rev, buffer); |
161 | |
161 | |
162 | if (strcmp(match_path, buffer)) |
162 | if (strcmp(match_path, buffer)) |
163 | return READ_TREE_RECURSIVE; |
163 | return READ_TREE_RECURSIVE; |
164 | |
164 | |
165 | if (S_ISDIR(mode)) { |
165 | if (S_ISDIR(mode)) { |
166 | state = 1; |
166 | state = 1; |
167 | ls_head(); |
167 | ls_head(); |
168 | return READ_TREE_RECURSIVE; |
168 | return READ_TREE_RECURSIVE; |
169 | } else { |
169 | } else { |
170 | print_object(sha1, buffer); |
170 | print_object(sha1, buffer); |
171 | return 0; |
171 | return 0; |
@@ -179,38 +179,38 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
179 | /* |
179 | /* |
180 | * Show a tree or a blob |
180 | * Show a tree or a blob |
181 | * rev: the commit pointing at the root tree object |
181 | * rev: the commit pointing at the root tree object |
182 | * path: path to tree or blob |
182 | * path: path to tree or blob |
183 | */ |
183 | */ |
184 | void cgit_print_tree(const char *rev, char *path) |
184 | void cgit_print_tree(const char *rev, char *path) |
185 | { |
185 | { |
186 | unsigned char sha1[20]; |
186 | unsigned char sha1[20]; |
187 | struct commit *commit; |
187 | struct commit *commit; |
188 | const char *paths[] = {path, NULL}; |
188 | const char *paths[] = {path, NULL}; |
189 | |
189 | |
190 | if (!rev) |
190 | if (!rev) |
191 | rev = cgit_query_head; |
191 | rev = ctx.qry.head; |
192 | |
192 | |
193 | curr_rev = xstrdup(rev); |
193 | curr_rev = xstrdup(rev); |
194 | if (get_sha1(rev, sha1)) { |
194 | if (get_sha1(rev, sha1)) { |
195 | cgit_print_error(fmt("Invalid revision name: %s", rev)); |
195 | cgit_print_error(fmt("Invalid revision name: %s", rev)); |
196 | return; |
196 | return; |
197 | } |
197 | } |
198 | commit = lookup_commit_reference(sha1); |
198 | commit = lookup_commit_reference(sha1); |
199 | if (!commit || parse_commit(commit)) { |
199 | if (!commit || parse_commit(commit)) { |
200 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
200 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
201 | return; |
201 | return; |
202 | } |
202 | } |
203 | |
203 | |
204 | html("path: <a href='"); |
204 | html("path: <a href='"); |
205 | html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); |
205 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); |
206 | html("'>root</a>"); |
206 | html("'>root</a>"); |
207 | |
207 | |
208 | if (path == NULL) { |
208 | if (path == NULL) { |
209 | ls_tree(commit->tree->object.sha1, NULL); |
209 | ls_tree(commit->tree->object.sha1, NULL); |
210 | return; |
210 | return; |
211 | } |
211 | } |
212 | |
212 | |
213 | match_path = path; |
213 | match_path = path; |
214 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); |
214 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); |
215 | ls_tail(); |
215 | ls_tail(); |
216 | } |
216 | } |
|