range-diff: fix regression in passing along diff options

In 73a834e9e2 ("range-diff: relieve callers of low-level configuration burden", 2018-07-22) we broke passing down options like --no-patch, --stat etc. Fix that regression, and add a test asserting the pre-73a834e9e2 behavior for some of these diff options. As noted in a change leading up to this ("range-diff doc: add a section about output stability", 2018-11-07) the output is not meant to be stable. So this regression test will likely need to be tweaked once we get a "proper" --stat option. See https://public-inbox.org/git/nycvar.QRO.7.76.6.1811071202480.39@tvgsbejvaqbjf.bet/ for a further explanation of the regression. The fix here is not the same as in Johannes's on-list patch, for reasons that'll be explained in a follow-up commit. The quoting of "EOF" here mirrors that of an earlier test. Perhaps that should be fixed, but let's leave that up to a later cleanup change. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Nov 9, 2018 at 10:18 UTC 4624185a67aa17104762a4bbff2b05727ef4cd83
2 files changed +54 -1
range-diff.c
+1 -1
@@ -433,7 +433,7 @@ int show_range_diff(const char *range1, const char *range2,
433 struct strbuf indent = STRBUF_INIT;
434
435 memcpy(&opts, diffopt, sizeof(opts));
436 - opts.output_format = DIFF_FORMAT_PATCH;
436 + opts.output_format |= DIFF_FORMAT_PATCH;
437 opts.flags.suppress_diff_headers = 1;
438 opts.flags.dual_color_diffed_diffs = dual_color;
439 opts.output_prefix = output_prefix_cb;
t/t3206-range-diff.sh
+53
@@ -122,6 +122,59 @@ test_expect_success 'changed commit' '
122 test_cmp expected actual
123 '
124
125 +test_expect_success 'changed commit with --no-patch diff option' '
126 + git range-diff --no-color --no-patch topic...changed >actual &&
127 + cat >expected <<-EOF &&
128 + 1: 4de457d = 1: a4b3333 s/5/A/
129 + 2: fccce22 = 2: f51d370 s/4/A/
130 + 3: 147e64e ! 3: 0559556 s/11/B/
131 + 4: a63e992 ! 4: d966c5c s/12/B/
132 + EOF
133 + test_cmp expected actual
134 +'
135 +
136 +test_expect_success 'changed commit with --stat diff option' '
137 + four_spaces=" " &&
138 + git range-diff --no-color --stat topic...changed >actual &&
139 + cat >expected <<-EOF &&
140 + 1: 4de457d = 1: a4b3333 s/5/A/
141 + a => b | 0
142 + 1 file changed, 0 insertions(+), 0 deletions(-)
143 + $four_spaces
144 + 2: fccce22 = 2: f51d370 s/4/A/
145 + a => b | 0
146 + 1 file changed, 0 insertions(+), 0 deletions(-)
147 + $four_spaces
148 + 3: 147e64e ! 3: 0559556 s/11/B/
149 + a => b | 0
150 + 1 file changed, 0 insertions(+), 0 deletions(-)
151 + $four_spaces
152 + @@ -10,7 +10,7 @@
153 + 9
154 + 10
155 + -11
156 + -+B
157 + ++BB
158 + 12
159 + 13
160 + 14
161 + 4: a63e992 ! 4: d966c5c s/12/B/
162 + a => b | 0
163 + 1 file changed, 0 insertions(+), 0 deletions(-)
164 + $four_spaces
165 + @@ -8,7 +8,7 @@
166 + @@
167 + 9
168 + 10
169 + - B
170 + + BB
171 + -12
172 + +B
173 + 13
174 + EOF
175 + test_cmp expected actual
176 +'
177 +
178 test_expect_success 'changed message' '
179 git range-diff --no-color topic...changed-message >actual &&
180 sed s/Z/\ /g >expected <<-EOF &&