revision.c: use skip_prefix() in handle_revision_pseudo_opt()

Instead of starts_with() and a bunch of magic numbers. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Jun 9, 2017 at 20:17 UTC 8b1d9136e1ca0125ad6f62667b039f1f59513e5a
1 file changed +9 -9
revision.c
+9 -9
@@ -2099,20 +2099,20 @@ static int handle_revision_pseudo_opt(const char *submodule,
2099 } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
2100 add_ref_exclusion(&revs->ref_excludes, optarg);
2101 return argcount;
2102 - } else if (starts_with(arg, "--branches=")) {
2102 + } else if (skip_prefix(arg, "--branches=", &optarg)) {
2103 struct all_refs_cb cb;
2104 init_all_refs_cb(&cb, revs, *flags);
2105 - for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
2105 + for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb);
2106 clear_ref_exclusion(&revs->ref_excludes);
2107 - } else if (starts_with(arg, "--tags=")) {
2107 + } else if (skip_prefix(arg, "--tags=", &optarg)) {
2108 struct all_refs_cb cb;
2109 init_all_refs_cb(&cb, revs, *flags);
2110 - for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
2110 + for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb);
2111 clear_ref_exclusion(&revs->ref_excludes);
2112 - } else if (starts_with(arg, "--remotes=")) {
2112 + } else if (skip_prefix(arg, "--remotes=", &optarg)) {
2113 struct all_refs_cb cb;
2114 init_all_refs_cb(&cb, revs, *flags);
2115 - for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
2115 + for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb);
2116 clear_ref_exclusion(&revs->ref_excludes);
2117 } else if (!strcmp(arg, "--reflog")) {
2118 add_reflogs_to_pending(revs, *flags);
@@ -2122,14 +2122,14 @@ static int handle_revision_pseudo_opt(const char *submodule,
2122 *flags ^= UNINTERESTING | BOTTOM;
2123 } else if (!strcmp(arg, "--no-walk")) {
2124 revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
2125 - } else if (starts_with(arg, "--no-walk=")) {
2125 + } else if (skip_prefix(arg, "--no-walk=", &optarg)) {
2126 /*
2127 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
2128 * not allowed, since the argument is optional.
2129 */
2130 - if (!strcmp(arg + 10, "sorted"))
2130 + if (!strcmp(optarg, "sorted"))
2131 revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
2132 - else if (!strcmp(arg + 10, "unsorted"))
2132 + else if (!strcmp(optarg, "unsorted"))
2133 revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
2134 else
2135 return error("invalid argument to --no-walk");