diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Trim the comments and dead code across the tree
Diffstat (limited to 'source/ui-plain.c')
| -rw-r--r-- | source/ui-plain.c | 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 16 insertions, 20 deletions
diff --git a/source/ui-plain.c b/source/ui-plain.c index b63b9c6..d3b4771 100644 --- a/source/ui-plain.c +++ b/source/ui-plain.c @@ -45,10 +45,10 @@ static int is_unsafe_type(const char *mimetype) } /* - * A nonzero return says the response has been written, error pages included, - * so the walk does not go on to report the path as missing. + * Writes the response for the object, error pages included, so the walk + * does not go on to report the path as missing. */ -static int print_object(const struct object_id *oid, const char *path) +static void print_object(const struct object_id *oid, const char *path) { enum object_type type; char *buf, *mimetype; @@ -57,7 +57,7 @@ static int print_object(const struct object_id *oid, const char *path) type = odb_read_object_info(the_repository->objects, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not Found", "Not found"); - return 1; + return; } // The limit counts kilobytes and is checked before the read, so a huge @@ -67,13 +67,13 @@ static int print_object(const struct object_id *oid, const char *path) cgit_print_error_page(413, "Content Too Large", "Object size (%luKB) exceeds limit (%dKB)", size / 1024, ctx.cfg.max_blob_size); - return 1; + return; } buf = odb_read_object(the_repository->objects, oid, &type, &size); if (!buf) { cgit_print_error_page(404, "Not Found", "Not found"); - return 1; + return; } mimetype = cgit_get_mimetype_for_filename(path); @@ -99,7 +99,6 @@ static int print_object(const struct object_id *oid, const char *path) html_raw(buf, size); free(mimetype); free(buf); - return 1; } static char *build_path(const char *base, int baselen, const char *path) @@ -110,8 +109,7 @@ static char *build_path(const char *base, int baselen, const char *path) return cgit_fmtalloc("%.*s/", baselen, base); } -static void print_dir(const struct object_id *oid, const char *base, - int baselen, const char *path) +static void print_dir(const char *base, int baselen, const char *path) { char *fullpath; const char *leading_slash; @@ -120,9 +118,8 @@ static void print_dir(const struct object_id *oid, const char *base, fullpath = build_path(base, baselen, path); leading_slash = (fullpath[0] == '/' ? "" : "/"); cgit_print_http_headers(); - // The listing is a full document of its own, so it carries the same - // doctype and charset as the layout pages or the browser would parse - // it in quirks mode. + // A full document of its own, and without the doctype and charset + // the browser would parse it in quirks mode. html("<!DOCTYPE html>\n<html lang='en'>\n<head>\n"); html("<meta charset='UTF-8'>\n"); htmlf("<title>%s", leading_slash); @@ -186,10 +183,10 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, if (walk->dir_len >= 0 && base->len == (size_t)walk->dir_len) { if (S_ISREG(mode) || S_ISLNK(mode)) { - if (print_object(oid, pathname)) - walk->response = RESPONSE_BLOB; + print_object(oid, pathname); + walk->response = RESPONSE_BLOB; } else if (S_ISDIR(mode)) { - print_dir(oid, base->buf, base->len, pathname); + print_dir(base->buf, base->len, pathname); walk->response = RESPONSE_LISTING; return READ_TREE_RECURSIVE; } @@ -217,10 +214,9 @@ void cgit_print_plain(void) struct object_id oid; struct commit *commit; int path_len = ctx.qry.path ? strlen(ctx.qry.path) : 0; - // A hand built pathspec leaves nowildcard_len at zero, which tells git - // the match may be a glob. It would then hand this walk every entry a - // pattern like * matches, and each one would be answered with its own - // set of HTTP headers inside the body of the first. + // nowildcard_len matches len so git treats the path as literal. As a + // glob, every entry a pattern like * matches would be answered with + // its own HTTP headers inside the body of the first. struct pathspec_item path_items = { .match = ctx.qry.path, .len = path_len, @@ -251,7 +247,7 @@ void cgit_print_plain(void) // itself, so the listing it would have opened is opened here. path_items.match = ""; walk.dir_len = -1; - print_dir(get_commit_tree_oid(commit), "", 0, ""); + print_dir("", 0, ""); walk.response = RESPONSE_LISTING; } else { walk.dir_len = dir_prefix_len(path_items.match); |
