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