提交 20aa7c59 编写于 作者: J Junio C Hamano

Merge branch 'nd/diff-parseopt'

A brown-paper-bag bugfix to a change already in 'master'.

* nd/diff-parseopt:
  parse-options: check empty value in OPT_INTEGER and OPT_ABBREV
  diff-parseopt: restore -U (no argument) behavior
  diff-parseopt: correct variable types that are used by parseopt
...@@ -5211,9 +5211,11 @@ static int diff_opt_unified(const struct option *opt, ...@@ -5211,9 +5211,11 @@ static int diff_opt_unified(const struct option *opt,
BUG_ON_OPT_NEG(unset); BUG_ON_OPT_NEG(unset);
options->context = strtol(arg, &s, 10); if (arg) {
if (*s) options->context = strtol(arg, &s, 10);
return error(_("%s expects a numerical value"), "--unified"); if (*s)
return error(_("%s expects a numerical value"), "--unified");
}
enable_patch_output(&options->output_format); enable_patch_output(&options->output_format);
return 0; return 0;
...@@ -5272,7 +5274,7 @@ static void prep_parse_options(struct diff_options *options) ...@@ -5272,7 +5274,7 @@ static void prep_parse_options(struct diff_options *options)
DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
OPT_CALLBACK_F('U', "unified", options, N_("<n>"), OPT_CALLBACK_F('U', "unified", options, N_("<n>"),
N_("generate diffs with <n> lines context"), N_("generate diffs with <n> lines context"),
PARSE_OPT_NONEG, diff_opt_unified), PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_unified),
OPT_BOOL('W', "function-context", &options->flags.funccontext, OPT_BOOL('W', "function-context", &options->flags.funccontext,
N_("generate diffs with <n> lines context")), N_("generate diffs with <n> lines context")),
OPT_BIT_F(0, "raw", &options->output_format, OPT_BIT_F(0, "raw", &options->output_format,
......
...@@ -169,7 +169,7 @@ struct diff_options { ...@@ -169,7 +169,7 @@ struct diff_options {
const char *prefix; const char *prefix;
int prefix_length; int prefix_length;
const char *stat_sep; const char *stat_sep;
long xdl_opts; int xdl_opts;
/* see Documentation/diff-options.txt */ /* see Documentation/diff-options.txt */
char **anchors; char **anchors;
......
...@@ -16,6 +16,9 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) ...@@ -16,6 +16,9 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
if (!arg) { if (!arg) {
v = unset ? 0 : DEFAULT_ABBREV; v = unset ? 0 : DEFAULT_ABBREV;
} else { } else {
if (!*arg)
return error(_("option `%s' expects a numerical value"),
opt->long_name);
v = strtol(arg, (char **)&arg, 10); v = strtol(arg, (char **)&arg, 10);
if (*arg) if (*arg)
return error(_("option `%s' expects a numerical value"), return error(_("option `%s' expects a numerical value"),
......
...@@ -195,6 +195,9 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p, ...@@ -195,6 +195,9 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,
} }
if (get_arg(p, opt, flags, &arg)) if (get_arg(p, opt, flags, &arg))
return -1; return -1;
if (!*arg)
return error(_("%s expects a numerical value"),
optname(opt, flags));
*(int *)opt->value = strtol(arg, (char **)&s, 10); *(int *)opt->value = strtol(arg, (char **)&s, 10);
if (*s) if (*s)
return error(_("%s expects a numerical value"), return error(_("%s expects a numerical value"),
......
...@@ -338,6 +338,8 @@ format-patch --inline --stdout initial..master^^ ...@@ -338,6 +338,8 @@ format-patch --inline --stdout initial..master^^
format-patch --stdout --cover-letter -n initial..master^ format-patch --stdout --cover-letter -n initial..master^
diff --abbrev initial..side diff --abbrev initial..side
diff -U initial..side
diff -U1 initial..side
diff -r initial..side diff -r initial..side
diff --stat initial..side diff --stat initial..side
diff -r --stat initial..side diff -r --stat initial..side
......
$ git diff -U1 initial..side
diff --git a/dir/sub b/dir/sub
index 35d242b..7289e35 100644
--- a/dir/sub
+++ b/dir/sub
@@ -2 +2,3 @@ A
B
+1
+2
diff --git a/file0 b/file0
index 01e79c3..f4615da 100644
--- a/file0
+++ b/file0
@@ -3 +3,4 @@
3
+A
+B
+C
diff --git a/file3 b/file3
new file mode 100644
index 0000000..7289e35
--- /dev/null
+++ b/file3
@@ -0,0 +1,4 @@
+A
+B
+1
+2
$
$ git diff -U2 initial..side
diff --git a/dir/sub b/dir/sub
index 35d242b..7289e35 100644
--- a/dir/sub
+++ b/dir/sub
@@ -1,2 +1,4 @@
A
B
+1
+2
diff --git a/file0 b/file0
index 01e79c3..f4615da 100644
--- a/file0
+++ b/file0
@@ -2,2 +2,5 @@
2
3
+A
+B
+C
diff --git a/file3 b/file3
new file mode 100644
index 0000000..7289e35
--- /dev/null
+++ b/file3
@@ -0,0 +1,4 @@
+A
+B
+1
+2
$
$ git diff -U initial..side
diff --git a/dir/sub b/dir/sub
index 35d242b..7289e35 100644
--- a/dir/sub
+++ b/dir/sub
@@ -1,2 +1,4 @@
A
B
+1
+2
diff --git a/file0 b/file0
index 01e79c3..f4615da 100644
--- a/file0
+++ b/file0
@@ -1,3 +1,6 @@
1
2
3
+A
+B
+C
diff --git a/file3 b/file3
new file mode 100644
index 0000000..7289e35
--- /dev/null
+++ b/file3
@@ -0,0 +1,4 @@
+A
+B
+1
+2
$
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册