Skip to content

Commit ef87cc7

Browse files
peffgitster
authored andcommitted
rev-parse: use skip_prefix when parsing options
Using skip_prefix lets us avoid manually-counted offsets into the argument string. This patch converts the simple and obvious cases. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7e07d5 commit ef87cc7

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

builtin/rev-parse.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
719719
for_each_ref(show_reference, NULL);
720720
continue;
721721
}
722-
if (starts_with(arg, "--disambiguate=")) {
723-
for_each_abbrev(arg + 15, show_abbrev, NULL);
722+
if (skip_prefix(arg, "--disambiguate=", &arg)) {
723+
for_each_abbrev(arg, show_abbrev, NULL);
724724
continue;
725725
}
726726
if (!strcmp(arg, "--bisect")) {
727727
for_each_ref_in("refs/bisect/bad", show_reference, NULL);
728728
for_each_ref_in("refs/bisect/good", anti_reference, NULL);
729729
continue;
730730
}
731-
if (starts_with(arg, "--branches=")) {
732-
for_each_glob_ref_in(show_reference, arg + 11,
731+
if (skip_prefix(arg, "--branches=", &arg)) {
732+
for_each_glob_ref_in(show_reference, arg,
733733
"refs/heads/", NULL);
734734
clear_ref_exclusion(&ref_excludes);
735735
continue;
@@ -739,8 +739,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
739739
clear_ref_exclusion(&ref_excludes);
740740
continue;
741741
}
742-
if (starts_with(arg, "--tags=")) {
743-
for_each_glob_ref_in(show_reference, arg + 7,
742+
if (skip_prefix(arg, "--tags=", &arg)) {
743+
for_each_glob_ref_in(show_reference, arg,
744744
"refs/tags/", NULL);
745745
clear_ref_exclusion(&ref_excludes);
746746
continue;
@@ -750,13 +750,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
750750
clear_ref_exclusion(&ref_excludes);
751751
continue;
752752
}
753-
if (starts_with(arg, "--glob=")) {
754-
for_each_glob_ref(show_reference, arg + 7, NULL);
753+
if (skip_prefix(arg, "--glob=", &arg)) {
754+
for_each_glob_ref(show_reference, arg, NULL);
755755
clear_ref_exclusion(&ref_excludes);
756756
continue;
757757
}
758-
if (starts_with(arg, "--remotes=")) {
759-
for_each_glob_ref_in(show_reference, arg + 10,
758+
if (skip_prefix(arg, "--remotes=", &arg)) {
759+
for_each_glob_ref_in(show_reference, arg,
760760
"refs/remotes/", NULL);
761761
clear_ref_exclusion(&ref_excludes);
762762
continue;
@@ -766,8 +766,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
766766
clear_ref_exclusion(&ref_excludes);
767767
continue;
768768
}
769-
if (starts_with(arg, "--exclude=")) {
770-
add_ref_exclusion(&ref_excludes, arg + 10);
769+
if (skip_prefix(arg, "--exclude=", &arg)) {
770+
add_ref_exclusion(&ref_excludes, arg);
771771
continue;
772772
}
773773
if (!strcmp(arg, "--show-toplevel")) {
@@ -849,20 +849,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
849849
}
850850
continue;
851851
}
852-
if (starts_with(arg, "--since=")) {
853-
show_datestring("--max-age=", arg+8);
852+
if (skip_prefix(arg, "--since=", &arg)) {
853+
show_datestring("--max-age=", arg);
854854
continue;
855855
}
856-
if (starts_with(arg, "--after=")) {
857-
show_datestring("--max-age=", arg+8);
856+
if (skip_prefix(arg, "--after=", &arg)) {
857+
show_datestring("--max-age=", arg);
858858
continue;
859859
}
860-
if (starts_with(arg, "--before=")) {
861-
show_datestring("--min-age=", arg+9);
860+
if (skip_prefix(arg, "--before=", &arg)) {
861+
show_datestring("--min-age=", arg);
862862
continue;
863863
}
864-
if (starts_with(arg, "--until=")) {
865-
show_datestring("--min-age=", arg+8);
864+
if (skip_prefix(arg, "--until=", &arg)) {
865+
show_datestring("--min-age=", arg);
866866
continue;
867867
}
868868
if (show_flag(arg) && verify)

0 commit comments

Comments
 (0)