Git fork

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

+107 -5
+6 -4
diff.c
··· 5211 5211 5212 5212 BUG_ON_OPT_NEG(unset); 5213 5213 5214 - options->context = strtol(arg, &s, 10); 5215 - if (*s) 5216 - return error(_("%s expects a numerical value"), "--unified"); 5214 + if (arg) { 5215 + options->context = strtol(arg, &s, 10); 5216 + if (*s) 5217 + return error(_("%s expects a numerical value"), "--unified"); 5218 + } 5217 5219 enable_patch_output(&options->output_format); 5218 5220 5219 5221 return 0; ··· 5272 5274 DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), 5273 5275 OPT_CALLBACK_F('U', "unified", options, N_("<n>"), 5274 5276 N_("generate diffs with <n> lines context"), 5275 - PARSE_OPT_NONEG, diff_opt_unified), 5277 + PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_unified), 5276 5278 OPT_BOOL('W', "function-context", &options->flags.funccontext, 5277 5279 N_("generate diffs with <n> lines context")), 5278 5280 OPT_BIT_F(0, "raw", &options->output_format,
+1 -1
diff.h
··· 169 169 const char *prefix; 170 170 int prefix_length; 171 171 const char *stat_sep; 172 - long xdl_opts; 172 + int xdl_opts; 173 173 174 174 /* see Documentation/diff-options.txt */ 175 175 char **anchors;
+3
parse-options-cb.c
··· 16 16 if (!arg) { 17 17 v = unset ? 0 : DEFAULT_ABBREV; 18 18 } else { 19 + if (!*arg) 20 + return error(_("option `%s' expects a numerical value"), 21 + opt->long_name); 19 22 v = strtol(arg, (char **)&arg, 10); 20 23 if (*arg) 21 24 return error(_("option `%s' expects a numerical value"),
+3
parse-options.c
··· 195 195 } 196 196 if (get_arg(p, opt, flags, &arg)) 197 197 return -1; 198 + if (!*arg) 199 + return error(_("%s expects a numerical value"), 200 + optname(opt, flags)); 198 201 *(int *)opt->value = strtol(arg, (char **)&s, 10); 199 202 if (*s) 200 203 return error(_("%s expects a numerical value"),
+2
t/t4013-diff-various.sh
··· 338 338 format-patch --stdout --cover-letter -n initial..master^ 339 339 340 340 diff --abbrev initial..side 341 + diff -U initial..side 342 + diff -U1 initial..side 341 343 diff -r initial..side 342 344 diff --stat initial..side 343 345 diff -r --stat initial..side
+29
t/t4013/diff.diff_-U1_initial..side
··· 1 + $ git diff -U1 initial..side 2 + diff --git a/dir/sub b/dir/sub 3 + index 35d242b..7289e35 100644 4 + --- a/dir/sub 5 + +++ b/dir/sub 6 + @@ -2 +2,3 @@ A 7 + B 8 + +1 9 + +2 10 + diff --git a/file0 b/file0 11 + index 01e79c3..f4615da 100644 12 + --- a/file0 13 + +++ b/file0 14 + @@ -3 +3,4 @@ 15 + 3 16 + +A 17 + +B 18 + +C 19 + diff --git a/file3 b/file3 20 + new file mode 100644 21 + index 0000000..7289e35 22 + --- /dev/null 23 + +++ b/file3 24 + @@ -0,0 +1,4 @@ 25 + +A 26 + +B 27 + +1 28 + +2 29 + $
+31
t/t4013/diff.diff_-U2_initial..side
··· 1 + $ git diff -U2 initial..side 2 + diff --git a/dir/sub b/dir/sub 3 + index 35d242b..7289e35 100644 4 + --- a/dir/sub 5 + +++ b/dir/sub 6 + @@ -1,2 +1,4 @@ 7 + A 8 + B 9 + +1 10 + +2 11 + diff --git a/file0 b/file0 12 + index 01e79c3..f4615da 100644 13 + --- a/file0 14 + +++ b/file0 15 + @@ -2,2 +2,5 @@ 16 + 2 17 + 3 18 + +A 19 + +B 20 + +C 21 + diff --git a/file3 b/file3 22 + new file mode 100644 23 + index 0000000..7289e35 24 + --- /dev/null 25 + +++ b/file3 26 + @@ -0,0 +1,4 @@ 27 + +A 28 + +B 29 + +1 30 + +2 31 + $
+32
t/t4013/diff.diff_-U_initial..side
··· 1 + $ git diff -U initial..side 2 + diff --git a/dir/sub b/dir/sub 3 + index 35d242b..7289e35 100644 4 + --- a/dir/sub 5 + +++ b/dir/sub 6 + @@ -1,2 +1,4 @@ 7 + A 8 + B 9 + +1 10 + +2 11 + diff --git a/file0 b/file0 12 + index 01e79c3..f4615da 100644 13 + --- a/file0 14 + +++ b/file0 15 + @@ -1,3 +1,6 @@ 16 + 1 17 + 2 18 + 3 19 + +A 20 + +B 21 + +C 22 + diff --git a/file3 b/file3 23 + new file mode 100644 24 + index 0000000..7289e35 25 + --- /dev/null 26 + +++ b/file3 27 + @@ -0,0 +1,4 @@ 28 + +A 29 + +B 30 + +1 31 + +2 32 + $