about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2013-03-03 17:10:19 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2013-03-04 09:12:54 -0500
commita6317505ead198c23925c93abbb0926f70e02861 (patch)
tree79eea985f4622431a98e6d879a7b6b5b30e6f02d
parentui-blob.c: Use a context structure in walk_tree() (diff)
downloadcgit-pink-a6317505ead198c23925c93abbb0926f70e02861.tar.gz
cgit-pink-a6317505ead198c23925c93abbb0926f70e02861.zip
ui-plain.c: Do not access match variable in print_*()
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>
Diffstat (limited to '')
-rw-r--r--ui-plain.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/ui-plain.c b/ui-plain.c
index c21d38f..c90ae59 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -54,7 +54,7 @@ static char *get_mimetype_from_file(const char *filename, const char *ext)
 	return result;
 }
 
-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;
@@ -65,13 +65,13 @@ static void print_object(const unsigned char *sha1, const char *path)
 	type = sha1_object_info(sha1, &size);
 	if (type == OBJ_BAD) {
 		html_status(404, "Not found", 0);
-		return;
+		return 0;
 	}
 
 	buf = read_sha1_file(sha1, &type, &size);
 	if (!buf) {
 		html_status(404, "Not found", 0);
-		return;
+		return 0;
 	}
 	ctx.page.mimetype = NULL;
 	ext = strrchr(path, '.');
@@ -97,9 +97,9 @@ static void print_object(const unsigned char *sha1, const char *path)
 	ctx.page.etag = sha1_to_hex(sha1);
 	cgit_print_http_headers(&ctx);
 	html_raw(buf, size);
-	match = 1;
 	if (freemime)
 		free(ctx.page.mimetype);
+	return 1;
 }
 
 static char *buildpath(const char *base, int baselen, const char *path)
@@ -138,7 +138,6 @@ static void print_dir(const unsigned char *sha1, const char *base,
 				fullpath);
 		html("</li>\n");
 	}
-	match = 2;
 }
 
 static void print_dir_entry(const unsigned char *sha1, const char *base,
@@ -156,7 +155,6 @@ 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");
-	match = 2;
 }
 
 static void print_dir_tail(void)
@@ -169,17 +167,20 @@ static int walk_tree(const unsigned char *sha1, const char *base, int 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);
+			match = 2;
 			return READ_TREE_RECURSIVE;
 		}
-	}
-	else if (baselen > match_baselen)
+	} else if (baselen > match_baselen) {
 		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 0;
 }
@@ -222,6 +223,7 @@ void cgit_print_plain(struct cgit_context *ctx)
 		path_items.match = "";
 		match_baselen = -1;
 		print_dir(commit->tree->object.sha1, "", 0, "");
+		match = 2;
 	}
 	else
 		match_baselen = basedir_len(path_items.match);
>Add startup GPLv3 note and URLJune McEnroe I am a degenerate. 2020-02-11Make sure -D_GNU_SOURCE ends up in CFLAGS on LinuxJune McEnroe 2020-02-11Add note about setting PKG_CONFIG_PATHJune McEnroe 2020-02-11Rename query ID on nick changeJune McEnroe 2020-02-11Call completeClear when closing a windowJune McEnroe 2020-02-11Don't insert color codes for non-mentionsJune McEnroe 2020-02-11Take first two words in colorMentionsJune McEnroe This lets phrases like "hi june" get colored, but still doesn't get carried away. 2020-02-11Use time_t for save signatureJune McEnroe It's actually more likely to be 64-bit than size_t anyway, and it eliminates some helper functions. Also don't error when reading an empty save file. 2020-02-11Set self.nick to * initiallyJune McEnroe Allows removing a bunch of checks that self.nick is set, and it's what the server usually calls you before registration. Never highlight notices as mentions. 2020-02-11Define ColorCap instead of hardcoding 100June McEnroe 2020-02-11Move hash to top of chat.hJune McEnroe 2020-02-11Move base64 out of chat.hJune McEnroe 2020-02-11Move XDG_SUBDIR out of chat.hJune McEnroe 2020-02-11Fix whois idle unit calculationJune McEnroe Rookie mistake. 2020-02-11Cast towupper to wchar_tJune McEnroe For some reason it takes and returns wint_t... 2020-02-11Cast set but unused variables to voidJune McEnroe 2020-02-11Declare strlcatJune McEnroe 2020-02-11Check if VDSUSP existsJune McEnroe 2020-02-11Fix completeReplace iterationJune McEnroe 2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe 2020-02-11Remove legacy codeJune McEnroe 2020-02-11Add INSTALLING section to READMEJune McEnroe