diff: fix --relative without arguments
PATCH v2 1/1 diff: fix --relative without arguments
From: Jacob Keller <[email protected]>
Recently, commit f7923a5ece00 ("diff: use skip_to_optional_val()", 2017-12-04) changed how we parsed some diff options, preferring skip_to_optional_val instead of a more complex skip_prefix() setup.
Unfortunately, this breaks --relative, because of the semantics of skip_to_optional_val. If no optional_val is given, then the function puts the empty string "" into the arg. Unfortunately, relative passes in options->prefix as the location for the optional argument, and expects this value to remain unchanged if no optional value was given.
This results in breaking --relative when no arguments are provided. This cascades into many failures of code flow that rely on this.
Partially revert the commit, and restore --relative option parsing to the previous working code.
Since no tests exist for --relative without options, add a new test which will help ensure no future regressions.
---
Actually perform the revert of --relative handling.
diff.c | 6 +++++- t/t4045-diff-relative.sh | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-)
diff.c +5 -1
@@ -4581,8 +4581,12 @@ int diff_opt_parse(struct diff_options *options, options->flags.rename_empty =1 ; else if (!strcmp(arg, "--no-rename-empty")) options->flags.rename_empty =0 ; - else if (skip_to_optional_val(arg, "--relative", &options->prefix)) + else if (!strcmp(arg, "--relative")) options->flags.relative_name =1 ; + else if (skip_prefix(arg, "--relative=", &arg)) { + options->flags.relative_name =1 ; + options->prefix = arg; + }/* xdiff options */ else if (!strcmp(arg, "--minimal"))
t/t4045-diff-relative.sh +5 -0
@@ -70,4 +70,9 @@ for type in diff numstat stat raw; do check_$type dir/file2 --relative=sub done +cd subdir +for type in diff numstat stat raw; do + check_$type file2 --relative +done + test_done
Signature · 1 line
2.15.1.477.g3ed0a2a61da8
Quoted 5 lines · Jacob Keller
From: Jacob Keller <[email protected]>
Recently, commit
f7923a5ece00("diff: useskip_to_optional_val()", 2017-12-04) changed how we parsed some diff options, preferringskip_to_optional_valinstead of a more complexskip_prefix()setup.
I'd expect a moral equivalent of this squashed in when Christian rerolls the skip-to-optional-val series (with helped-by: attribution to you, probably). It does not make much sense to leave the initial breakage like this one in the history.
Thanks.
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Jacob Keller
From: Jacob Keller <[email protected]>
Recently, commit
f7923a5ece00("diff: useskip_to_optional_val()", 2017-12-04) changed how we parsed some diff options, preferringskip_to_optional_valinstead of a more complexskip_prefix()setup.
Quoted 6 lines
I'd expect a moral equivalent of this squashed in when Christian rerolls the skip-to-optional-val series (with helped-by: attribution to you, probably). It does not make much sense to leave the initial breakage like this one in the history.
Thanks.
Quite correct. I'll be sending a patch with just new tests shortly.
Thanks,
Jake