* [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches
@ 2014-01-10 13:55 cgit
2014-01-10 13:55 ` [PATCH 2/2] cgit.c: Fix comment on bit mask hack cgit
2014-01-10 16:05 ` [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches Jason
0 siblings, 2 replies; 4+ messages in thread
From: cgit @ 2014-01-10 13:55 UTC (permalink / 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] cgit.c: Fix comment on bit mask hack
2014-01-10 13:55 [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches cgit
@ 2014-01-10 13:55 ` cgit
2014-01-10 16:06 ` Jason
2014-01-10 16:05 ` [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches Jason
1 sibling, 1 reply; 4+ messages in thread
From: cgit @ 2014-01-10 13:55 UTC (permalink / raw)
* Formatting and spelling fixes.
* A bit mask with the size of one byte only allows for storing 8 (not
255!) different flags.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
cgit.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/cgit.c b/cgit.c
index f4262d8..d74b0f3 100644
--- a/cgit.c
+++ b/cgit.c
@@ -885,14 +885,16 @@ static void cgit_parse_args(int argc, const char **argv)
ctx.qry.ofs = atoi(argv[i] + 6);
} 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
- * currently 0. By setting all bits high before
- * scanning we make sure that any in-repo cgitrc
- * snapshot setting is respected by scan_tree().
- * BTW: we assume that there'll never be more than
- * 255 different snapshot formats supported by cgit...
+ /*
+ * HACK: The global snapshot bit mask defines the set
+ * of allowed snapshot formats, but the config file
+ * hasn't been parsed yet so the mask is currently 0.
+ * By setting all bits high before scanning we make
+ * sure that any in-repo cgitrc snapshot setting is
+ * respected by scan_tree().
+ *
+ * NOTE: We assume that there aren't more than 8
+ * different snapshot formats supported by cgit...
*/
ctx.cfg.snapshots = 0xFF;
scan++;
--
1.8.5.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches
2014-01-10 13:55 [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches cgit
2014-01-10 13:55 ` [PATCH 2/2] cgit.c: Fix comment on bit mask hack cgit
@ 2014-01-10 16:05 ` Jason
1 sibling, 0 replies; 4+ messages in thread
From: Jason @ 2014-01-10 16:05 UTC (permalink / raw)
Seems reasonable. Merged.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] cgit.c: Fix comment on bit mask hack
2014-01-10 13:55 ` [PATCH 2/2] cgit.c: Fix comment on bit mask hack cgit
@ 2014-01-10 16:06 ` Jason
0 siblings, 0 replies; 4+ messages in thread
From: Jason @ 2014-01-10 16:06 UTC (permalink / raw)
On Fri, Jan 10, 2014 at 2:55 PM, Lukas Fleischer <cgit at cryptocrack.de> wrote:
> * A bit mask with the size of one byte only allows for storing 8 (not
> 255!) different flags.
Haha. Merged, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-10 16:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-10 13:55 [PATCH 1/2] cgit.c: Use "else" for mutually exclusive branches cgit
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
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).