@@ -231,6 +231,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
231
231
232
232
int git_diff_basic_config (const char * var , const char * value , void * cb )
233
233
{
234
+ const char * name ;
235
+
234
236
if (!strcmp (var , "diff.renamelimit" )) {
235
237
diff_rename_limit_default = git_config_int (var , value );
236
238
return 0 ;
@@ -239,8 +241,9 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
239
241
if (userdiff_config (var , value ) < 0 )
240
242
return -1 ;
241
243
242
- if (starts_with (var , "diff.color." ) || starts_with (var , "color.diff." )) {
243
- int slot = parse_diff_color_slot (var + 11 );
244
+ if (skip_prefix (var , "diff.color." , & name ) ||
245
+ skip_prefix (var , "color.diff." , & name )) {
246
+ int slot = parse_diff_color_slot (name );
244
247
if (slot < 0 )
245
248
return 0 ;
246
249
if (!value )
@@ -2341,6 +2344,7 @@ static void builtin_diff(const char *name_a,
2341
2344
} else {
2342
2345
/* Crazy xdl interfaces.. */
2343
2346
const char * diffopts = getenv ("GIT_DIFF_OPTS" );
2347
+ const char * v ;
2344
2348
xpparam_t xpp ;
2345
2349
xdemitconf_t xecfg ;
2346
2350
struct emit_callback ecbdata ;
@@ -2379,10 +2383,10 @@ static void builtin_diff(const char *name_a,
2379
2383
xdiff_set_find_func (& xecfg , pe -> pattern , pe -> cflags );
2380
2384
if (!diffopts )
2381
2385
;
2382
- else if (starts_with (diffopts , "--unified=" ))
2383
- xecfg .ctxlen = strtoul (diffopts + 10 , NULL , 10 );
2384
- else if (starts_with (diffopts , "-u" ))
2385
- xecfg .ctxlen = strtoul (diffopts + 2 , NULL , 10 );
2386
+ else if (skip_prefix (diffopts , "--unified=" , & v ))
2387
+ xecfg .ctxlen = strtoul (v , NULL , 10 );
2388
+ else if (skip_prefix (diffopts , "-u" , & v ))
2389
+ xecfg .ctxlen = strtoul (v , NULL , 10 );
2386
2390
if (o -> word_diff )
2387
2391
init_diff_words_data (& ecbdata , o , one , two );
2388
2392
xdi_diff_outf (& mf1 , & mf2 , fn_out_consume , & ecbdata ,
@@ -3609,17 +3613,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3609
3613
options -> output_format |= DIFF_FORMAT_SHORTSTAT ;
3610
3614
else if (!strcmp (arg , "-X" ) || !strcmp (arg , "--dirstat" ))
3611
3615
return parse_dirstat_opt (options , "" );
3612
- else if (starts_with (arg , "-X" ))
3613
- return parse_dirstat_opt (options , arg + 2 );
3614
- else if (starts_with (arg , "--dirstat=" ))
3615
- return parse_dirstat_opt (options , arg + 10 );
3616
+ else if (skip_prefix (arg , "-X" , & arg ))
3617
+ return parse_dirstat_opt (options , arg );
3618
+ else if (skip_prefix (arg , "--dirstat=" , & arg ))
3619
+ return parse_dirstat_opt (options , arg );
3616
3620
else if (!strcmp (arg , "--cumulative" ))
3617
3621
return parse_dirstat_opt (options , "cumulative" );
3618
3622
else if (!strcmp (arg , "--dirstat-by-file" ))
3619
3623
return parse_dirstat_opt (options , "files" );
3620
- else if (starts_with (arg , "--dirstat-by-file=" )) {
3624
+ else if (skip_prefix (arg , "--dirstat-by-file=" , & arg )) {
3621
3625
parse_dirstat_opt (options , "files" );
3622
- return parse_dirstat_opt (options , arg + 18 );
3626
+ return parse_dirstat_opt (options , arg );
3623
3627
}
3624
3628
else if (!strcmp (arg , "--check" ))
3625
3629
options -> output_format |= DIFF_FORMAT_CHECKDIFF ;
@@ -3669,9 +3673,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3669
3673
DIFF_OPT_CLR (options , RENAME_EMPTY );
3670
3674
else if (!strcmp (arg , "--relative" ))
3671
3675
DIFF_OPT_SET (options , RELATIVE_NAME );
3672
- else if (starts_with (arg , "--relative=" )) {
3676
+ else if (skip_prefix (arg , "--relative=" , & arg )) {
3673
3677
DIFF_OPT_SET (options , RELATIVE_NAME );
3674
- options -> prefix = arg + 11 ;
3678
+ options -> prefix = arg ;
3675
3679
}
3676
3680
3677
3681
/* xdiff options */
@@ -3722,8 +3726,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3722
3726
DIFF_OPT_CLR (options , FOLLOW_RENAMES );
3723
3727
else if (!strcmp (arg , "--color" ))
3724
3728
options -> use_color = 1 ;
3725
- else if (starts_with (arg , "--color=" )) {
3726
- int value = git_config_colorbool (NULL , arg + 8 );
3729
+ else if (skip_prefix (arg , "--color=" , & arg )) {
3730
+ int value = git_config_colorbool (NULL , arg );
3727
3731
if (value < 0 )
3728
3732
return error ("option `color' expects \"always\", \"auto\", or \"never\"" );
3729
3733
options -> use_color = value ;
@@ -3734,29 +3738,28 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3734
3738
options -> use_color = 1 ;
3735
3739
options -> word_diff = DIFF_WORDS_COLOR ;
3736
3740
}
3737
- else if (starts_with (arg , "--color-words=" )) {
3741
+ else if (skip_prefix (arg , "--color-words=" , & arg )) {
3738
3742
options -> use_color = 1 ;
3739
3743
options -> word_diff = DIFF_WORDS_COLOR ;
3740
- options -> word_regex = arg + 14 ;
3744
+ options -> word_regex = arg ;
3741
3745
}
3742
3746
else if (!strcmp (arg , "--word-diff" )) {
3743
3747
if (options -> word_diff == DIFF_WORDS_NONE )
3744
3748
options -> word_diff = DIFF_WORDS_PLAIN ;
3745
3749
}
3746
- else if (starts_with (arg , "--word-diff=" )) {
3747
- const char * type = arg + 12 ;
3748
- if (!strcmp (type , "plain" ))
3750
+ else if (skip_prefix (arg , "--word-diff=" , & arg )) {
3751
+ if (!strcmp (arg , "plain" ))
3749
3752
options -> word_diff = DIFF_WORDS_PLAIN ;
3750
- else if (!strcmp (type , "color" )) {
3753
+ else if (!strcmp (arg , "color" )) {
3751
3754
options -> use_color = 1 ;
3752
3755
options -> word_diff = DIFF_WORDS_COLOR ;
3753
3756
}
3754
- else if (!strcmp (type , "porcelain" ))
3757
+ else if (!strcmp (arg , "porcelain" ))
3755
3758
options -> word_diff = DIFF_WORDS_PORCELAIN ;
3756
- else if (!strcmp (type , "none" ))
3759
+ else if (!strcmp (arg , "none" ))
3757
3760
options -> word_diff = DIFF_WORDS_NONE ;
3758
3761
else
3759
- die ("bad --word-diff argument: %s" , type );
3762
+ die ("bad --word-diff argument: %s" , arg );
3760
3763
}
3761
3764
else if ((argcount = parse_long_opt ("word-diff-regex" , av , & optarg ))) {
3762
3765
if (options -> word_diff == DIFF_WORDS_NONE )
@@ -3779,13 +3782,13 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3779
3782
else if (!strcmp (arg , "--ignore-submodules" )) {
3780
3783
DIFF_OPT_SET (options , OVERRIDE_SUBMODULE_CONFIG );
3781
3784
handle_ignore_submodules_arg (options , "all" );
3782
- } else if (starts_with (arg , "--ignore-submodules=" )) {
3785
+ } else if (skip_prefix (arg , "--ignore-submodules=" , & arg )) {
3783
3786
DIFF_OPT_SET (options , OVERRIDE_SUBMODULE_CONFIG );
3784
- handle_ignore_submodules_arg (options , arg + 20 );
3787
+ handle_ignore_submodules_arg (options , arg );
3785
3788
} else if (!strcmp (arg , "--submodule" ))
3786
3789
DIFF_OPT_SET (options , SUBMODULE_LOG );
3787
- else if (starts_with (arg , "--submodule=" ))
3788
- return parse_submodule_opt (options , arg + 12 );
3790
+ else if (skip_prefix (arg , "--submodule=" , & arg ))
3791
+ return parse_submodule_opt (options , arg );
3789
3792
3790
3793
/* misc options */
3791
3794
else if (!strcmp (arg , "-z" ))
@@ -3820,8 +3823,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3820
3823
}
3821
3824
else if (!strcmp (arg , "--abbrev" ))
3822
3825
options -> abbrev = DEFAULT_ABBREV ;
3823
- else if (starts_with (arg , "--abbrev=" )) {
3824
- options -> abbrev = strtoul (arg + 9 , NULL , 10 );
3826
+ else if (skip_prefix (arg , "--abbrev=" , & arg )) {
3827
+ options -> abbrev = strtoul (arg , NULL , 10 );
3825
3828
if (options -> abbrev < MINIMUM_ABBREV )
3826
3829
options -> abbrev = MINIMUM_ABBREV ;
3827
3830
else if (40 < options -> abbrev )
0 commit comments