about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2014-01-10 14:55:30 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2014-01-10 17:05:34 +0100
commit441e748564aff49932d02987cd2bdcfbb623c295 (patch)
tree39a22d071da1af3d3621fe4d35d3492d68bc106c
parentui-snapshot.c: Do not reinvent suffixcmp() (diff)
downloadcgit-pink-441e748564aff49932d02987cd2bdcfbb623c295.tar.gz
cgit-pink-441e748564aff49932d02987cd2bdcfbb623c295.zip
cgit.c: Use "else" for mutually exclusive branches
When parsing command line arguments, no pair of command line options can
ever match simultaneously. Use "else if" blocks to reflect this. This
change improves both readability and speed.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r--cgit.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/cgit.c b/cgit.c
index e31962d..f4262d8 100644
--- a/cgit.c
+++ b/cgit.c
@@ -865,35 +865,26 @@ static void cgit_parse_args(int argc, const char **argv)
 	for (i = 1; i < argc; i++) {
 		if (!prefixcmp(argv[i], "--cache=")) {
 			ctx.cfg.cache_root = xstrdup(argv[i] + 8);
-		}
-		if (!strcmp(argv[i], "--nocache")) {
+		} else if (!strcmp(argv[i], "--nocache")) {
 			ctx.cfg.nocache = 1;
-		}
-		if (!strcmp(argv[i], "--nohttp")) {
+		} else if (!strcmp(argv[i], "--nohttp")) {
 			ctx.env.no_http = "1";
-		}
-		if (!prefixcmp(argv[i], "--query=")) {
+		} else if (!prefixcmp(argv[i], "--query=")) {
 			ctx.qry.raw = xstrdup(argv[i] + 8);
-		}
-		if (!prefixcmp(argv[i], "--repo=")) {
+		} else if (!prefixcmp(argv[i], "--repo=")) {
 			ctx.qry.repo = xstrdup(argv[i] + 7);
-		}
-		if (!prefixcmp(argv[i], "--page=")) {
+		} else if (!prefixcmp(argv[i], "--page=")) {
 			ctx.qry.page = xstrdup(argv[i] + 7);
-		}
-		if (!prefixcmp(argv[i], "--head=")) {
+		} else if (!prefixcmp(argv[i], "--head=")) {
 			ctx.qry.head = xstrdup(argv[i] + 7);
 			ctx.qry.has_symref = 1;
-		}
-		if (!prefixcmp(argv[i], "--sha1=")) {
+		} else if (!prefixcmp(argv[i], "--sha1=")) {
 			ctx.qry.sha1 = xstrdup(argv[i] + 7);
 			ctx.qry.has_sha1 = 1;
-		}
-		if (!prefixcmp(argv[i], "--ofs=")) {
+		} else if (!prefixcmp(argv[i], "--ofs=")) {
 			ctx.qry.ofs = atoi(argv[i] + 6);
-		}
-		if (!prefixcmp(argv[i], "--scan-tree=") ||
-		    !prefixcmp(argv[i], "--scan-path=")) {
+		} else if (!prefixcmp(argv[i], "--scan-tree=") ||
+		           !prefixcmp(argv[i], "--scan-path=")) {
 			/* HACK: the global snapshot bitmask defines the
 			 * set of allowed snapshot formats, but the config
 			 * file hasn't been parsed yet so the mask is
35 -0500'>2019-01-13Enable warnings in libeditJune McEnroe 2019-01-13Show full path in RPS1June McEnroe 2019-01-13Shorten $HOME to ~ in prompt expansionJune McEnroe 2019-01-13Document PSlitJune McEnroe 2019-01-13Document PS0June McEnroe 2019-01-13Set PS0 in cashJune McEnroe 2019-01-13Add PS0June McEnroe 2019-01-13Change default ENV from cashrc to env.shJune McEnroe 2019-01-13Use colours in cash promptsJune McEnroe 2019-01-12Set PSlit like NetBSD shJune McEnroe 2019-01-12Install gnupg2 from pkgsrc and symlink gpgJune McEnroe 2019-01-12Reference cash builtin man pages in cash.1 SEE ALSOJune McEnroe 2019-01-12Restore cash builtin man page datesJune McEnroe 2019-01-12Use local libeditJune McEnroe 2019-01-12Replace libedit MakefileJune McEnroe 2019-01-11Import /usr/src/lib/libedit from NetBSD 8.0June McEnroe 2019-01-11Add PSlit for prompt escapesJune McEnroe 2019-01-11Don't make depend automaticallyJune McEnroe