diff options
-rw-r--r-- | ui-plain.c | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -11,8 +11,10 @@ | |||
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | 13 | ||
14 | int match_baselen; | 14 | struct walk_tree_context { |
15 | int match; | 15 | int match_baselen; |
16 | int match; | ||
17 | }; | ||
16 | 18 | ||
17 | static char *get_mimetype_from_file(const char *filename, const char *ext) | 19 | static char *get_mimetype_from_file(const char *filename, const char *ext) |
18 | { | 20 | { |
@@ -166,18 +168,20 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | |||
166 | const char *pathname, unsigned mode, int stage, | 168 | const char *pathname, unsigned mode, int stage, |
167 | void *cbdata) | 169 | void *cbdata) |
168 | { | 170 | { |
169 | if (baselen == match_baselen) { | 171 | struct walk_tree_context *walk_tree_ctx = cbdata; |
172 | |||
173 | if (baselen == walk_tree_ctx->match_baselen) { | ||
170 | if (S_ISREG(mode)) { | 174 | if (S_ISREG(mode)) { |
171 | if (print_object(sha1, pathname)) | 175 | if (print_object(sha1, pathname)) |
172 | match = 1; | 176 | walk_tree_ctx->match = 1; |
173 | } else if (S_ISDIR(mode)) { | 177 | } else if (S_ISDIR(mode)) { |
174 | print_dir(sha1, base, baselen, pathname); | 178 | print_dir(sha1, base, baselen, pathname); |
175 | match = 2; | 179 | walk_tree_ctx->match = 2; |
176 | return READ_TREE_RECURSIVE; | 180 | return READ_TREE_RECURSIVE; |
177 | } | 181 | } |
178 | } else if (baselen > match_baselen) { | 182 | } else if (baselen > walk_tree_ctx->match_baselen) { |
179 | print_dir_entry(sha1, base, baselen, pathname, mode); | 183 | print_dir_entry(sha1, base, baselen, pathname, mode); |
180 | match = 2; | 184 | walk_tree_ctx->match = 2; |
181 | } else if (S_ISDIR(mode)) { | 185 | } else if (S_ISDIR(mode)) { |
182 | return READ_TREE_RECURSIVE; | 186 | return READ_TREE_RECURSIVE; |
183 | } | 187 | } |
@@ -206,6 +210,9 @@ void cgit_print_plain(struct cgit_context *ctx) | |||
206 | .nr = 1, | 210 | .nr = 1, |
207 | .items = &path_items | 211 | .items = &path_items |
208 | }; | 212 | }; |
213 | struct walk_tree_context walk_tree_ctx = { | ||
214 | .match = 0 | ||
215 | }; | ||
209 | 216 | ||
210 | if (!rev) | 217 | if (!rev) |
211 | rev = ctx->qry.head; | 218 | rev = ctx->qry.head; |
@@ -221,15 +228,15 @@ void cgit_print_plain(struct cgit_context *ctx) | |||
221 | } | 228 | } |
222 | if (!path_items.match) { | 229 | if (!path_items.match) { |
223 | path_items.match = ""; | 230 | path_items.match = ""; |
224 | match_baselen = -1; | 231 | walk_tree_ctx.match_baselen = -1; |
225 | print_dir(commit->tree->object.sha1, "", 0, ""); | 232 | print_dir(commit->tree->object.sha1, "", 0, ""); |
226 | match = 2; | 233 | walk_tree_ctx.match = 2; |
227 | } | 234 | } |
228 | else | 235 | else |
229 | match_baselen = basedir_len(path_items.match); | 236 | walk_tree_ctx.match_baselen = basedir_len(path_items.match); |
230 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, NULL); | 237 | read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); |
231 | if (!match) | 238 | if (!walk_tree_ctx.match) |
232 | html_status(404, "Not found", 0); | 239 | html_status(404, "Not found", 0); |
233 | else if (match == 2) | 240 | else if (walk_tree_ctx.match == 2) |
234 | print_dir_tail(); | 241 | print_dir_tail(); |
235 | } | 242 | } |