X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/db8b8cb9467625cb8d9ecb67863aa67590e59cc0..74ebf82229829bbdbe74a4d9a7b6f29d2889dfc8:/ui-plain.c diff --git a/ui-plain.c b/ui-plain.c index 27c6dae..8b0badd 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -10,8 +10,7 @@ #include "html.h" #include "ui-shared.h" -char *curr_rev; -char *match_path; +int match_baselen; int match; static void print_object(const unsigned char *sha1, const char *path) @@ -57,12 +56,21 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *cbdata) { - if (S_ISDIR(mode)) + if (baselen == match_baselen) { + if (S_ISREG(mode)) + print_object(sha1, pathname); + } + else if (S_ISDIR(mode)) return READ_TREE_RECURSIVE; - if (S_ISREG(mode)) - print_object(sha1, pathname); + return 0; +} +static int basedir_len(const char *path) +{ + char *p = strrchr(path, '/'); + if (p) + return p - path + 1; return 0; } @@ -76,7 +84,6 @@ void cgit_print_plain(struct cgit_context *ctx) if (!rev) rev = ctx->qry.head; - curr_rev = xstrdup(rev); if (get_sha1(rev, sha1)) { html_status(404, "Not found", 0); return; @@ -86,8 +93,8 @@ void cgit_print_plain(struct cgit_context *ctx) html_status(404, "Not found", 0); return; } - match_path = ctx->qry.path; - read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); + match_baselen = basedir_len(paths[0]); + read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); if (!match) html_status(404, "Not found", 0); }