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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 15, 2017 at 16:05 UTC ef87cc79dff1fa0d16ad4d67646afeba9ce11a6c
1 file changed +20 -20
builtin/rev-parse.c
+20 -20
@@ -719,8 +719,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
719 for_each_ref(show_reference, NULL);
720 continue;
721 }
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);
724 continue;
725 }
726 if (!strcmp(arg, "--bisect")) {
@@ -728,8 +728,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
728 for_each_ref_in("refs/bisect/good", anti_reference, NULL);
729 continue;
730 }
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,
733 "refs/heads/", NULL);
734 clear_ref_exclusion(&ref_excludes);
735 continue;
@@ -739,8 +739,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
739 clear_ref_exclusion(&ref_excludes);
740 continue;
741 }
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,
744 "refs/tags/", NULL);
745 clear_ref_exclusion(&ref_excludes);
746 continue;
@@ -750,13 +750,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
750 clear_ref_exclusion(&ref_excludes);
751 continue;
752 }
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);
755 clear_ref_exclusion(&ref_excludes);
756 continue;
757 }
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,
760 "refs/remotes/", NULL);
761 clear_ref_exclusion(&ref_excludes);
762 continue;
@@ -766,8 +766,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
766 clear_ref_exclusion(&ref_excludes);
767 continue;
768 }
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);
771 continue;
772 }
773 if (!strcmp(arg, "--show-toplevel")) {
@@ -849,20 +849,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
849 }
850 continue;
851 }
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);
854 continue;
855 }
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);
858 continue;
859 }
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);
862 continue;
863 }
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);
866 continue;
867 }
868 if (show_flag(arg) && verify)