231
232
int git_diff_basic_config(const char *var, const char *value, void *cb)
233
{
234
+ const char *name;
235
+
236
if (!strcmp(var, "diff.renamelimit")) {
237
diff_rename_limit_default = git_config_int(var, value);
238
return 0;
241
if (userdiff_config(var, value) < 0)
242
return -1;
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);
247
if (slot < 0)
248
return 0;
249
if (!value)
2344
} else {
2345
/* Crazy xdl interfaces.. */
2346
const char *diffopts = getenv("GIT_DIFF_OPTS");
2347
+ const char *v;
2348
xpparam_t xpp;
2349
xdemitconf_t xecfg;
2350
struct emit_callback ecbdata;
2383
xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
2384
if (!diffopts)
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);
2390
if (o->word_diff)
2391
init_diff_words_data(&ecbdata, o, one, two);
2392
xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
3613
options->output_format |= DIFF_FORMAT_SHORTSTAT;
3614
else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
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);
3620
else if (!strcmp(arg, "--cumulative"))
3621
return parse_dirstat_opt(options, "cumulative");
3622
else if (!strcmp(arg, "--dirstat-by-file"))
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)) {
3625
parse_dirstat_opt(options, "files");
3622
- return parse_dirstat_opt(options, arg + 18);
3626
+ return parse_dirstat_opt(options, arg);
3627
}
3628
else if (!strcmp(arg, "--check"))
3629
options->output_format |= DIFF_FORMAT_CHECKDIFF;
3673
DIFF_OPT_CLR(options, RENAME_EMPTY);
3674
else if (!strcmp(arg, "--relative"))
3675
DIFF_OPT_SET(options, RELATIVE_NAME);
3672
- else if (starts_with(arg, "--relative=")) {
3676
+ else if (skip_prefix(arg, "--relative=", &arg)) {
3677
DIFF_OPT_SET(options, RELATIVE_NAME);
3674
- options->prefix = arg + 11;
3678
+ options->prefix = arg;
3679
}
3680
3681
/* xdiff options */
3726
DIFF_OPT_CLR(options, FOLLOW_RENAMES);
3727
else if (!strcmp(arg, "--color"))
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);
3731
if (value < 0)
3732
return error("option `color' expects \"always\", \"auto\", or \"never\"");
3733
options->use_color = value;
3738
options->use_color = 1;
3739
options->word_diff = DIFF_WORDS_COLOR;
3740
}
3737
- else if (starts_with(arg, "--color-words=")) {
3741
+ else if (skip_prefix(arg, "--color-words=", &arg)) {
3742
options->use_color = 1;
3743
options->word_diff = DIFF_WORDS_COLOR;
3740
- options->word_regex = arg + 14;
3744
+ options->word_regex = arg;
3745
}
3746
else if (!strcmp(arg, "--word-diff")) {
3747
if (options->word_diff == DIFF_WORDS_NONE)
3748
options->word_diff = DIFF_WORDS_PLAIN;
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"))
3752
options->word_diff = DIFF_WORDS_PLAIN;
3750
- else if (!strcmp(type, "color")) {
3753
+ else if (!strcmp(arg, "color")) {
3754
options->use_color = 1;
3755
options->word_diff = DIFF_WORDS_COLOR;
3756
}
3754
- else if (!strcmp(type, "porcelain"))
3757
+ else if (!strcmp(arg, "porcelain"))
3758
options->word_diff = DIFF_WORDS_PORCELAIN;
3756
- else if (!strcmp(type, "none"))
3759
+ else if (!strcmp(arg, "none"))
3760
options->word_diff = DIFF_WORDS_NONE;
3761
else
3759
- die("bad --word-diff argument: %s", type);
3762
+ die("bad --word-diff argument: %s", arg);
3763
}
3764
else if ((argcount = parse_long_opt("word-diff-regex", av, &optarg))) {
3765
if (options->word_diff == DIFF_WORDS_NONE)
3782
else if (!strcmp(arg, "--ignore-submodules")) {
3783
DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
3784
handle_ignore_submodules_arg(options, "all");
3782
- } else if (starts_with(arg, "--ignore-submodules=")) {
3785
+ } else if (skip_prefix(arg, "--ignore-submodules=", &arg)) {
3786
DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
3784
- handle_ignore_submodules_arg(options, arg + 20);
3787
+ handle_ignore_submodules_arg(options, arg);
3788
} else if (!strcmp(arg, "--submodule"))
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);
3792
3793
/* misc options */
3794
else if (!strcmp(arg, "-z"))
3823
}
3824
else if (!strcmp(arg, "--abbrev"))
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);
3828
if (options->abbrev < MINIMUM_ABBREV)
3829
options->abbrev = MINIMUM_ABBREV;
3830
else if (40 < options->abbrev)