@matheusbsbs / matheus-bagliano / commits / b810cbbde9
Fork 0

diff --cc: a lost line at the beginning of the file is shown incorrectly

When combine-diff inspected the diff from one parent to the merge result, it misinterpreted a header in the form @@ -l,k +0,0 @@. This hunk header means that K lines were removed from the beginning of the file, so the lost lines must be queued to the sline that represents the first line of the merge result, but we incremented our pointer incorrectly and ended up queuing it to the second line, which in turn made the lossage appear _after_ the first line. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 22, 2009 at 14:48 UTC b810cbbde9232cbe9a3841edccc5b606bbd3a82e
2 files changed +93 -7
combine-diff.c
+9 -7
@@ -164,20 +164,22 @@ static void consume_line(void *state_, char *line, unsigned long len)
164 &state->nb, &state->nn))
165 return;
166 state->lno = state->nb;
167 - if (!state->nb)
168 - /* @@ -1,2 +0,0 @@ to remove the
169 - * first two lines...
170 - */
171 - state->nb = 1;
172 - if (state->nn == 0)
167 + if (state->nn == 0) {
168 /* @@ -X,Y +N,0 @@ removed Y lines
169 * that would have come *after* line N
170 * in the result. Our lost buckets hang
171 * to the line after the removed lines,
172 + *
173 + * Note that this is correct even when N == 0,
174 + * in which case the hunk removes the first
175 + * line in the file.
176 */
177 state->lost_bucket = &state->sline[state->nb];
179 - else
178 + if (!state->nb)
179 + state->nb = 1;
180 + } else {
181 state->lost_bucket = &state->sline[state->nb-1];
182 + }
183 if (!state->sline[state->nb-1].p_lno)
184 state->sline[state->nb-1].p_lno =
185 xcalloc(state->num_parent,
t/t4038-diff-combined.sh new
+84
@@ -0,0 +1,84 @@
1 +#!/bin/sh
2 +
3 +test_description='combined diff'
4 +
5 +. ./test-lib.sh
6 +
7 +setup_helper () {
8 + one=$1 branch=$2 side=$3 &&
9 +
10 + git branch $side $branch &&
11 + for l in $one two three fyra
12 + do
13 + echo $l
14 + done >file &&
15 + git add file &&
16 + test_tick &&
17 + git commit -m $branch &&
18 + git checkout $side &&
19 + for l in $one two three quatro
20 + do
21 + echo $l
22 + done >file &&
23 + git add file &&
24 + test_tick &&
25 + git commit -m $side &&
26 + test_must_fail git merge $branch &&
27 + for l in $one three four
28 + do
29 + echo $l
30 + done >file &&
31 + git add file &&
32 + test_tick &&
33 + git commit -m "merge $branch into $side"
34 +}
35 +
36 +verify_helper () {
37 + it=$1 &&
38 +
39 + # Ignore lines that were removed only from the other parent
40 + sed -e '
41 + 1,/^@@@/d
42 + /^ -/d
43 + s/^\(.\)./\1/
44 + ' "$it" >"$it.actual.1" &&
45 + sed -e '
46 + 1,/^@@@/d
47 + /^- /d
48 + s/^.\(.\)/\1/
49 + ' "$it" >"$it.actual.2" &&
50 +
51 + git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
52 + test_cmp "$it.expect.1" "$it.actual.1" &&
53 +
54 + git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
55 + test_cmp "$it.expect.2" "$it.actual.2"
56 +}
57 +
58 +test_expect_success setup '
59 + >file &&
60 + git add file &&
61 + test_tick &&
62 + git commit -m initial &&
63 +
64 + git branch withone &&
65 + git branch sansone &&
66 +
67 + git checkout withone &&
68 + setup_helper one withone sidewithone &&
69 +
70 + git checkout sansone &&
71 + setup_helper "" sansone sidesansone
72 +'
73 +
74 +test_expect_success 'check combined output (1)' '
75 + git show sidewithone -- >sidewithone &&
76 + verify_helper sidewithone
77 +'
78 +
79 +test_expect_failure 'check combined output (2)' '
80 + git show sidesansone -- >sidesansone &&
81 + verify_helper sidesansone
82 +'
83 +
84 +test_done