@@ -1725,8 +1725,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1725
1725
revs -> max_count = atoi (argv [1 ]);
1726
1726
revs -> no_walk = 0 ;
1727
1727
return 2 ;
1728
- } else if (starts_with (arg , "-n" )) {
1729
- revs -> max_count = atoi (arg + 2 );
1728
+ } else if (skip_prefix (arg , "-n" , & optarg )) {
1729
+ revs -> max_count = atoi (optarg );
1730
1730
revs -> no_walk = 0 ;
1731
1731
} else if ((argcount = parse_long_opt ("max-age" , argv , & optarg ))) {
1732
1732
revs -> max_age = atoi (optarg );
@@ -1785,16 +1785,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1785
1785
} else if (!strcmp (arg , "--author-date-order" )) {
1786
1786
revs -> sort_order = REV_SORT_BY_AUTHOR_DATE ;
1787
1787
revs -> topo_order = 1 ;
1788
- } else if (starts_with (arg , "--early-output" )) {
1789
- int count = 100 ;
1790
- switch (arg [14 ]) {
1791
- case '=' :
1792
- count = atoi (arg + 15 );
1793
- /* Fallthrough */
1794
- case 0 :
1795
- revs -> topo_order = 1 ;
1796
- revs -> early_output = count ;
1797
- }
1788
+ } else if (!strcmp (arg , "--early-output" )) {
1789
+ revs -> early_output = 100 ;
1790
+ revs -> topo_order = 1 ;
1791
+ } else if (skip_prefix (arg , "--early-output=" , & optarg )) {
1792
+ if (strtoul_ui (optarg , 10 , & revs -> early_output ) < 0 )
1793
+ die ("'%s': not a non-negative integer" , optarg );
1794
+ revs -> topo_order = 1 ;
1798
1795
} else if (!strcmp (arg , "--parents" )) {
1799
1796
revs -> rewrite_parents = 1 ;
1800
1797
revs -> print_parents = 1 ;
@@ -1810,13 +1807,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1810
1807
revs -> min_parents = 2 ;
1811
1808
} else if (!strcmp (arg , "--no-merges" )) {
1812
1809
revs -> max_parents = 1 ;
1813
- } else if (starts_with (arg , "--min-parents=" )) {
1814
- revs -> min_parents = atoi (arg + 14 );
1815
- } else if (starts_with (arg , "--no-min-parents" )) {
1810
+ } else if (skip_prefix (arg , "--min-parents=" , & optarg )) {
1811
+ revs -> min_parents = atoi (optarg );
1812
+ } else if (! strcmp (arg , "--no-min-parents" )) {
1816
1813
revs -> min_parents = 0 ;
1817
- } else if (starts_with (arg , "--max-parents=" )) {
1818
- revs -> max_parents = atoi (arg + 14 );
1819
- } else if (starts_with (arg , "--no-max-parents" )) {
1814
+ } else if (skip_prefix (arg , "--max-parents=" , & optarg )) {
1815
+ revs -> max_parents = atoi (optarg );
1816
+ } else if (! strcmp (arg , "--no-max-parents" )) {
1820
1817
revs -> max_parents = -1 ;
1821
1818
} else if (!strcmp (arg , "--boundary" )) {
1822
1819
revs -> boundary = 1 ;
@@ -1897,14 +1894,15 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1897
1894
revs -> verbose_header = 1 ;
1898
1895
revs -> pretty_given = 1 ;
1899
1896
get_commit_format (NULL , revs );
1900
- } else if (starts_with (arg , "--pretty=" ) || starts_with (arg , "--format=" )) {
1897
+ } else if (skip_prefix (arg , "--pretty=" , & optarg ) ||
1898
+ skip_prefix (arg , "--format=" , & optarg )) {
1901
1899
/*
1902
1900
* Detached form ("--pretty X" as opposed to "--pretty=X")
1903
1901
* not allowed, since the argument is optional.
1904
1902
*/
1905
1903
revs -> verbose_header = 1 ;
1906
1904
revs -> pretty_given = 1 ;
1907
- get_commit_format (arg + 9 , revs );
1905
+ get_commit_format (optarg , revs );
1908
1906
} else if (!strcmp (arg , "--expand-tabs" )) {
1909
1907
revs -> expand_tabs_in_log = 8 ;
1910
1908
} else if (!strcmp (arg , "--no-expand-tabs" )) {
@@ -1922,26 +1920,23 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1922
1920
revs -> show_signature = 1 ;
1923
1921
} else if (!strcmp (arg , "--no-show-signature" )) {
1924
1922
revs -> show_signature = 0 ;
1925
- } else if (!strcmp (arg , "--show-linear-break" ) ||
1926
- starts_with (arg , "--show-linear-break=" )) {
1927
- if (starts_with (arg , "--show-linear-break=" ))
1928
- revs -> break_bar = xstrdup (arg + 20 );
1929
- else
1930
- revs -> break_bar = " .........." ;
1923
+ } else if (!strcmp (arg , "--show-linear-break" )) {
1924
+ revs -> break_bar = " .........." ;
1931
1925
revs -> track_linear = 1 ;
1932
1926
revs -> track_first_time = 1 ;
1933
- } else if (starts_with (arg , "--show-notes=" ) ||
1934
- starts_with (arg , "--notes=" )) {
1927
+ } else if (skip_prefix (arg , "--show-linear-break=" , & optarg )) {
1928
+ revs -> break_bar = xstrdup (optarg );
1929
+ revs -> track_linear = 1 ;
1930
+ revs -> track_first_time = 1 ;
1931
+ } else if (skip_prefix (arg , "--show-notes=" , & optarg ) ||
1932
+ skip_prefix (arg , "--notes=" , & optarg )) {
1935
1933
struct strbuf buf = STRBUF_INIT ;
1936
1934
revs -> show_notes = 1 ;
1937
1935
revs -> show_notes_given = 1 ;
1938
- if (starts_with (arg , "--show-notes" )) {
1939
- if (revs -> notes_opt .use_default_notes < 0 )
1940
- revs -> notes_opt .use_default_notes = 1 ;
1941
- strbuf_addstr (& buf , arg + 13 );
1942
- }
1943
- else
1944
- strbuf_addstr (& buf , arg + 8 );
1936
+ if (starts_with (arg , "--show-notes=" ) &&
1937
+ revs -> notes_opt .use_default_notes < 0 )
1938
+ revs -> notes_opt .use_default_notes = 1 ;
1939
+ strbuf_addstr (& buf , optarg );
1945
1940
expand_notes_ref (& buf );
1946
1941
string_list_append (& revs -> notes_opt .extra_notes_refs ,
1947
1942
strbuf_detach (& buf , NULL ));
@@ -1978,8 +1973,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1978
1973
revs -> abbrev = 0 ;
1979
1974
} else if (!strcmp (arg , "--abbrev" )) {
1980
1975
revs -> abbrev = DEFAULT_ABBREV ;
1981
- } else if (starts_with (arg , "--abbrev=" )) {
1982
- revs -> abbrev = strtoul (arg + 9 , NULL , 10 );
1976
+ } else if (skip_prefix (arg , "--abbrev=" , & optarg )) {
1977
+ revs -> abbrev = strtoul (optarg , NULL , 10 );
1983
1978
if (revs -> abbrev < MINIMUM_ABBREV )
1984
1979
revs -> abbrev = MINIMUM_ABBREV ;
1985
1980
else if (revs -> abbrev > 40 )
@@ -2140,20 +2135,20 @@ static int handle_revision_pseudo_opt(const char *submodule,
2140
2135
} else if ((argcount = parse_long_opt ("exclude" , argv , & optarg ))) {
2141
2136
add_ref_exclusion (& revs -> ref_excludes , optarg );
2142
2137
return argcount ;
2143
- } else if (starts_with (arg , "--branches=" )) {
2138
+ } else if (skip_prefix (arg , "--branches=" , & optarg )) {
2144
2139
struct all_refs_cb cb ;
2145
2140
init_all_refs_cb (& cb , revs , * flags );
2146
- for_each_glob_ref_in (handle_one_ref , arg + 11 , "refs/heads/" , & cb );
2141
+ for_each_glob_ref_in (handle_one_ref , optarg , "refs/heads/" , & cb );
2147
2142
clear_ref_exclusion (& revs -> ref_excludes );
2148
- } else if (starts_with (arg , "--tags=" )) {
2143
+ } else if (skip_prefix (arg , "--tags=" , & optarg )) {
2149
2144
struct all_refs_cb cb ;
2150
2145
init_all_refs_cb (& cb , revs , * flags );
2151
- for_each_glob_ref_in (handle_one_ref , arg + 7 , "refs/tags/" , & cb );
2146
+ for_each_glob_ref_in (handle_one_ref , optarg , "refs/tags/" , & cb );
2152
2147
clear_ref_exclusion (& revs -> ref_excludes );
2153
- } else if (starts_with (arg , "--remotes=" )) {
2148
+ } else if (skip_prefix (arg , "--remotes=" , & optarg )) {
2154
2149
struct all_refs_cb cb ;
2155
2150
init_all_refs_cb (& cb , revs , * flags );
2156
- for_each_glob_ref_in (handle_one_ref , arg + 10 , "refs/remotes/" , & cb );
2151
+ for_each_glob_ref_in (handle_one_ref , optarg , "refs/remotes/" , & cb );
2157
2152
clear_ref_exclusion (& revs -> ref_excludes );
2158
2153
} else if (!strcmp (arg , "--reflog" )) {
2159
2154
add_reflogs_to_pending (revs , * flags );
@@ -2163,14 +2158,14 @@ static int handle_revision_pseudo_opt(const char *submodule,
2163
2158
* flags ^= UNINTERESTING | BOTTOM ;
2164
2159
} else if (!strcmp (arg , "--no-walk" )) {
2165
2160
revs -> no_walk = REVISION_WALK_NO_WALK_SORTED ;
2166
- } else if (starts_with (arg , "--no-walk=" )) {
2161
+ } else if (skip_prefix (arg , "--no-walk=" , & optarg )) {
2167
2162
/*
2168
2163
* Detached form ("--no-walk X" as opposed to "--no-walk=X")
2169
2164
* not allowed, since the argument is optional.
2170
2165
*/
2171
- if (!strcmp (arg + 10 , "sorted" ))
2166
+ if (!strcmp (optarg , "sorted" ))
2172
2167
revs -> no_walk = REVISION_WALK_NO_WALK_SORTED ;
2173
- else if (!strcmp (arg + 10 , "unsorted" ))
2168
+ else if (!strcmp (optarg , "unsorted" ))
2174
2169
revs -> no_walk = REVISION_WALK_NO_WALK_UNSORTED ;
2175
2170
else
2176
2171
return error ("invalid argument to --no-walk" );
0 commit comments