From: cgit at cryptocrack.de (Lukas Fleischer)
Subject: [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches
Date: Fri, 10 Jan 2014 14:55:30 +0100 [thread overview]
Message-ID: <1389362131-13202-1-git-send-email-cgit@cryptocrack.de> (raw)
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 at cryptocrack.de>
---
Based on the patches I sent earlier today.
cgit.c | 29 ++++++++++-------------------
1 file 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
--
1.8.5.2
next reply other threads:[~2014-01-10 13:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-10 13:55 cgit [this message]
2014-01-10 13:55 ` [PATCH 2/2] cgit.c: Fix comment on bit mask hack cgit
2014-01-10 16:06 ` Jason
2014-01-10 16:05 ` [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches Jason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1389362131-13202-1-git-send-email-cgit@cryptocrack.de \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).