History

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.

Lukas Fleischer committed 12 years ago

Commit 441e7481 parent e7116791 file · +10 −19Browse files

Unified · Split

cgit.c+10−19
@@ -865,35 +865,26 @@ static void cgit_parse_args(int argc, const char **argv) · 864 unmodified lines
865 for (i = 1; i < argc; i++) {865 for (i = 1; i < argc; i++) {
866 if (!prefixcmp(argv[i], "--cache=")) {866 if (!prefixcmp(argv[i], "--cache=")) {
867 ctx.cfg.cache_root = xstrdup(argv[i] + 8);867 ctx.cfg.cache_root = xstrdup(argv[i] + 8);
868 }868 } else if (!strcmp(argv[i], "--nocache")) {
869 if (!strcmp(argv[i], "--nocache")) {
870 ctx.cfg.nocache = 1;869 ctx.cfg.nocache = 1;
871 }870 } else if (!strcmp(argv[i], "--nohttp")) {
872 if (!strcmp(argv[i], "--nohttp")) {
873 ctx.env.no_http = "1";871 ctx.env.no_http = "1";
874 }872 } else if (!prefixcmp(argv[i], "--query=")) {
875 if (!prefixcmp(argv[i], "--query=")) {
876 ctx.qry.raw = xstrdup(argv[i] + 8);873 ctx.qry.raw = xstrdup(argv[i] + 8);
877 }874 } else if (!prefixcmp(argv[i], "--repo=")) {
878 if (!prefixcmp(argv[i], "--repo=")) {
879 ctx.qry.repo = xstrdup(argv[i] + 7);875 ctx.qry.repo = xstrdup(argv[i] + 7);
880 }876 } else if (!prefixcmp(argv[i], "--page=")) {
881 if (!prefixcmp(argv[i], "--page=")) {
882 ctx.qry.page = xstrdup(argv[i] + 7);877 ctx.qry.page = xstrdup(argv[i] + 7);
883 }878 } else if (!prefixcmp(argv[i], "--head=")) {
884 if (!prefixcmp(argv[i], "--head=")) {
885 ctx.qry.head = xstrdup(argv[i] + 7);879 ctx.qry.head = xstrdup(argv[i] + 7);
886 ctx.qry.has_symref = 1;880 ctx.qry.has_symref = 1;
887 }881 } else if (!prefixcmp(argv[i], "--sha1=")) {
888 if (!prefixcmp(argv[i], "--sha1=")) {
889 ctx.qry.sha1 = xstrdup(argv[i] + 7);882 ctx.qry.sha1 = xstrdup(argv[i] + 7);
890 ctx.qry.has_sha1 = 1;883 ctx.qry.has_sha1 = 1;
891 }884 } else if (!prefixcmp(argv[i], "--ofs=")) {
892 if (!prefixcmp(argv[i], "--ofs=")) {
893 ctx.qry.ofs = atoi(argv[i] + 6);885 ctx.qry.ofs = atoi(argv[i] + 6);
894 }886 } else if (!prefixcmp(argv[i], "--scan-tree=") ||
895 if (!prefixcmp(argv[i], "--scan-tree=") ||887 !prefixcmp(argv[i], "--scan-path=")) {
896 !prefixcmp(argv[i], "--scan-path=")) {
897 /* HACK: the global snapshot bitmask defines the888 /* HACK: the global snapshot bitmask defines the
898 * set of allowed snapshot formats, but the config889 * set of allowed snapshot formats, but the config
899 * file hasn't been parsed yet so the mask is890 * file hasn't been parsed yet so the mask is