diff --git a/diff.c b/diff.c index 397e38b41cc6fa..1771b2c444c005 100644 --- a/diff.c +++ b/diff.c @@ -60,8 +60,8 @@ static int diff_suppress_blank_empty; static enum git_colorbool diff_use_color_default = GIT_COLOR_UNKNOWN; static int diff_color_moved_default; static int diff_color_moved_ws_default; -static int diff_context_default = 3; -static int diff_interhunk_context_default; +static unsigned int diff_context_default = 3; +static unsigned int diff_interhunk_context_default; static char *diff_word_regex_cfg; static struct external_diff external_diff_cfg; static char *diff_order_file_cfg; @@ -382,16 +382,17 @@ int git_diff_ui_config(const char *var, const char *value, return 0; } if (!strcmp(var, "diff.context")) { - diff_context_default = git_config_int(var, value, ctx->kvi); - if (diff_context_default < 0) + int val = git_config_int(var, value, ctx->kvi); + if (val < 0) return -1; + diff_context_default = val; return 0; } if (!strcmp(var, "diff.interhunkcontext")) { - diff_interhunk_context_default = git_config_int(var, value, - ctx->kvi); - if (diff_interhunk_context_default < 0) + int val = git_config_int(var, value, ctx->kvi); + if (val < 0) return -1; + diff_interhunk_context_default = val; return 0; } if (!strcmp(var, "diff.renames")) { @@ -5924,9 +5925,12 @@ static int diff_opt_unified(const struct option *opt, BUG_ON_OPT_NEG(unset); if (arg) { - options->context = strtol(arg, &s, 10); + long val = strtol(arg, &s, 10); if (*s) return error(_("%s expects a numerical value"), "--unified"); + if (val < 0) + return error(_("%s expects a non-negative integer"), "--unified"); + options->context = val; } enable_patch_output(&options->output_format); @@ -6111,9 +6115,8 @@ struct option *add_diff_options(const struct option *opts, OPT_CALLBACK_F(0, "default-prefix", options, NULL, N_("use default prefixes a/ and b/"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_default_prefix), - OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext, - N_("show context between diff hunks up to the specified number of lines"), - PARSE_OPT_NONEG), + OPT_UNSIGNED(0, "inter-hunk-context", &options->interhunkcontext, + N_("show context between diff hunks up to the specified number of lines")), OPT_CALLBACK_F(0, "output-indicator-new", &options->output_indicators[OUTPUT_INDICATOR_NEW], N_(""), diff --git a/diff.h b/diff.h index 7eb84aadf40c41..bb5cddaf3499e9 100644 --- a/diff.h +++ b/diff.h @@ -294,9 +294,9 @@ struct diff_options { enum git_colorbool use_color; /* Number of context lines to generate in patch output. */ - int context; + unsigned int context; - int interhunkcontext; + unsigned int interhunkcontext; /* Affects the way detection logic for complete rewrites, renames and * copies. diff --git a/parse-options.h b/parse-options.h index 706de9729f6b3f..c0a3a3dcae0535 100644 --- a/parse-options.h +++ b/parse-options.h @@ -116,7 +116,10 @@ typedef int parse_opt_subcommand_fn(int argc, const char **argv, * mask of parse_opt_option_flags. * PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs) * PARSE_OPT_NOARG: says that this option does not take an argument - * PARSE_OPT_NONEG: says that this option cannot be negated + * PARSE_OPT_NONEG: says that this option cannot be negated (i.e. + * prevents --no-