|
diff --git a/ui-tree.c b/ui-tree.c index 5a2dd3f..9a837e2 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -53,25 +53,26 @@ static void print_object(const unsigned char *sha1, char *path) |
53 | start = idx + 1; |
53 | start = idx + 1; |
54 | } |
54 | } |
55 | idx++; |
55 | idx++; |
56 | } |
56 | } |
57 | htmlf(linefmt, ++lineno); |
57 | htmlf(linefmt, ++lineno); |
58 | html_txt(buf + start); |
58 | html_txt(buf + start); |
59 | html("</td></tr>\n"); |
59 | html("</td></tr>\n"); |
60 | html("</table>\n"); |
60 | html("</table>\n"); |
61 | } |
61 | } |
62 | |
62 | |
63 | |
63 | |
64 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
64 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
65 | const char *pathname, unsigned int mode, int stage) |
65 | const char *pathname, unsigned int mode, int stage, |
| |
66 | void *cbdata) |
66 | { |
67 | { |
67 | char *name; |
68 | char *name; |
68 | char *fullpath; |
69 | char *fullpath; |
69 | enum object_type type; |
70 | enum object_type type; |
70 | unsigned long size = 0; |
71 | unsigned long size = 0; |
71 | |
72 | |
72 | name = xstrdup(pathname); |
73 | name = xstrdup(pathname); |
73 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
74 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
74 | ctx.qry.path ? "/" : "", name); |
75 | ctx.qry.path ? "/" : "", name); |
75 | |
76 | |
76 | if (!S_ISGITLINK(mode)) { |
77 | if (!S_ISGITLINK(mode)) { |
77 | type = sha1_object_info(sha1, &size); |
78 | type = sha1_object_info(sha1, &size); |
@@ -134,31 +135,32 @@ static void ls_tail() |
134 | static void ls_tree(const unsigned char *sha1, char *path) |
135 | static void ls_tree(const unsigned char *sha1, char *path) |
135 | { |
136 | { |
136 | struct tree *tree; |
137 | struct tree *tree; |
137 | |
138 | |
138 | tree = parse_tree_indirect(sha1); |
139 | tree = parse_tree_indirect(sha1); |
139 | if (!tree) { |
140 | if (!tree) { |
140 | cgit_print_error(fmt("Not a tree object: %s", |
141 | cgit_print_error(fmt("Not a tree object: %s", |
141 | sha1_to_hex(sha1))); |
142 | sha1_to_hex(sha1))); |
142 | return; |
143 | return; |
143 | } |
144 | } |
144 | |
145 | |
145 | ls_head(); |
146 | ls_head(); |
146 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
147 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item, NULL); |
147 | ls_tail(); |
148 | ls_tail(); |
148 | } |
149 | } |
149 | |
150 | |
150 | |
151 | |
151 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
152 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
152 | const char *pathname, unsigned mode, int stage) |
153 | const char *pathname, unsigned mode, int stage, |
| |
154 | void *cbdata) |
153 | { |
155 | { |
154 | static int state; |
156 | static int state; |
155 | static char buffer[PATH_MAX]; |
157 | static char buffer[PATH_MAX]; |
156 | char *url; |
158 | char *url; |
157 | |
159 | |
158 | if (state == 0) { |
160 | if (state == 0) { |
159 | memcpy(buffer, base, baselen); |
161 | memcpy(buffer, base, baselen); |
160 | strcpy(buffer+baselen, pathname); |
162 | strcpy(buffer+baselen, pathname); |
161 | url = cgit_pageurl(ctx.qry.repo, "tree", |
163 | url = cgit_pageurl(ctx.qry.repo, "tree", |
162 | fmt("h=%s&path=%s", curr_rev, buffer)); |
164 | fmt("h=%s&path=%s", curr_rev, buffer)); |
163 | html("/"); |
165 | html("/"); |
164 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, |
166 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, |
@@ -167,25 +169,25 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
167 | if (strcmp(match_path, buffer)) |
169 | if (strcmp(match_path, buffer)) |
168 | return READ_TREE_RECURSIVE; |
170 | return READ_TREE_RECURSIVE; |
169 | |
171 | |
170 | if (S_ISDIR(mode)) { |
172 | if (S_ISDIR(mode)) { |
171 | state = 1; |
173 | state = 1; |
172 | ls_head(); |
174 | ls_head(); |
173 | return READ_TREE_RECURSIVE; |
175 | return READ_TREE_RECURSIVE; |
174 | } else { |
176 | } else { |
175 | print_object(sha1, buffer); |
177 | print_object(sha1, buffer); |
176 | return 0; |
178 | return 0; |
177 | } |
179 | } |
178 | } |
180 | } |
179 | ls_item(sha1, base, baselen, pathname, mode, stage); |
181 | ls_item(sha1, base, baselen, pathname, mode, stage, NULL); |
180 | return 0; |
182 | return 0; |
181 | } |
183 | } |
182 | |
184 | |
183 | |
185 | |
184 | /* |
186 | /* |
185 | * Show a tree or a blob |
187 | * Show a tree or a blob |
186 | * rev: the commit pointing at the root tree object |
188 | * rev: the commit pointing at the root tree object |
187 | * path: path to tree or blob |
189 | * path: path to tree or blob |
188 | */ |
190 | */ |
189 | void cgit_print_tree(const char *rev, char *path) |
191 | void cgit_print_tree(const char *rev, char *path) |
190 | { |
192 | { |
191 | unsigned char sha1[20]; |
193 | unsigned char sha1[20]; |
@@ -207,15 +209,15 @@ void cgit_print_tree(const char *rev, char *path) |
207 | } |
209 | } |
208 | |
210 | |
209 | html("path: <a href='"); |
211 | html("path: <a href='"); |
210 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); |
212 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); |
211 | html("'>root</a>"); |
213 | html("'>root</a>"); |
212 | |
214 | |
213 | if (path == NULL) { |
215 | if (path == NULL) { |
214 | ls_tree(commit->tree->object.sha1, NULL); |
216 | ls_tree(commit->tree->object.sha1, NULL); |
215 | return; |
217 | return; |
216 | } |
218 | } |
217 | |
219 | |
218 | match_path = path; |
220 | match_path = path; |
219 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); |
221 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); |
220 | ls_tail(); |
222 | ls_tail(); |
221 | } |
223 | } |
|