From: Jacob Keller <jacob.e.keller@intel.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Christian Couder <christian.couder@gmail.com>,
Jacob Keller <jacob.keller@gmail.com>
Subject: [PATCH v2] diff: fix --relative without arguments
Date: Wed, 6 Dec 2017 16:59:29 -0800 [thread overview]
Message-ID: <20171207005929.24109-1-jacob.e.keller@intel.com> (raw)
From: Jacob Keller <jacob.keller@gmail.com>
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.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
Actually perform the revert of --relative handling.
diff.c | 6 +++++-
t/t4045-diff-relative.sh | 5 +++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/diff.c b/diff.c
index b62e4b61b564..1919afb4f104 100644
--- a/diff.c
+++ b/diff.c
@@ -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"))
diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh
index 3950f5034d31..41e4f59b2ffb 100755
--- a/t/t4045-diff-relative.sh
+++ b/t/t4045-diff-relative.sh
@@ -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
--
2.15.1.477.g3ed0a2a61da8
next reply other threads:[~2017-12-07 0:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 0:59 Jacob Keller [this message]
2017-12-07 15:26 ` [PATCH v2] diff: fix --relative without arguments Junio C Hamano
2017-12-07 19:01 ` Jacob Keller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171207005929.24109-1-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).