Move all code setting the match variable to walk_tree().
This allows for easily moving this variable into a context structure
without having to pass the context to print_*().
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-static void print_object(const unsigned char *sha1, const char *path)
+static int print_object(const unsigned char *sha1, const char *path)
{
enum object_type type;
char *buf, *ext;
{
enum object_type type;
char *buf, *ext;
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
html_status(404, "Not found", 0);
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
html_status(404, "Not found", 0);
}
buf = read_sha1_file(sha1, &type, &size);
if (!buf) {
html_status(404, "Not found", 0);
}
buf = read_sha1_file(sha1, &type, &size);
if (!buf) {
html_status(404, "Not found", 0);
}
ctx.page.mimetype = NULL;
ext = strrchr(path, '.');
}
ctx.page.mimetype = NULL;
ext = strrchr(path, '.');
ctx.page.etag = sha1_to_hex(sha1);
cgit_print_http_headers(&ctx);
html_raw(buf, size);
ctx.page.etag = sha1_to_hex(sha1);
cgit_print_http_headers(&ctx);
html_raw(buf, size);
if (freemime)
free(ctx.page.mimetype);
if (freemime)
free(ctx.page.mimetype);
}
static char *buildpath(const char *base, int baselen, const char *path)
}
static char *buildpath(const char *base, int baselen, const char *path)
fullpath);
html("</li>\n");
}
fullpath);
html("</li>\n");
}
}
static void print_dir_entry(const unsigned char *sha1, const char *base,
}
static void print_dir_entry(const unsigned char *sha1, const char *base,
cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
fullpath);
html("</li>\n");
cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
fullpath);
html("</li>\n");
}
static void print_dir_tail(void)
}
static void print_dir_tail(void)
void *cbdata)
{
if (baselen == match_baselen) {
void *cbdata)
{
if (baselen == match_baselen) {
- if (S_ISREG(mode))
- print_object(sha1, pathname);
- else if (S_ISDIR(mode)) {
+ if (S_ISREG(mode)) {
+ if (print_object(sha1, pathname))
+ match = 1;
+ } else if (S_ISDIR(mode)) {
print_dir(sha1, base, baselen, pathname);
print_dir(sha1, base, baselen, pathname);
return READ_TREE_RECURSIVE;
}
return READ_TREE_RECURSIVE;
}
- }
- else if (baselen > match_baselen)
+ } else if (baselen > match_baselen) {
print_dir_entry(sha1, base, baselen, pathname, mode);
print_dir_entry(sha1, base, baselen, pathname, mode);
- else if (S_ISDIR(mode))
+ match = 2;
+ } else if (S_ISDIR(mode)) {
return READ_TREE_RECURSIVE;
return READ_TREE_RECURSIVE;
path_items.match = "";
match_baselen = -1;
print_dir(commit->tree->object.sha1, "", 0, "");
path_items.match = "";
match_baselen = -1;
print_dir(commit->tree->object.sha1, "", 0, "");
}
else
match_baselen = basedir_len(path_items.match);
}
else
match_baselen = basedir_len(path_items.match);