Skip to content

Commit edc7f0a

Browse files
committed
Merge branch 'mk/combine-diff-context-horizon-fix'
"git diff -c -p" was not showing a deleted line from a hunk when another hunk immediately begins where the earlier one ends. * mk/combine-diff-context-horizon-fix: combine-diff.c: Fix output when changes are exactly 3 lines apart
2 parents 911439a + aac3857 commit edc7f0a

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

combine-diff.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,11 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
518518
unsigned long k;
519519

520520
/* Paint a few lines before the first interesting line. */
521-
while (j < i)
522-
sline[j++].flag |= mark | no_pre_delete;
521+
while (j < i) {
522+
if (!(sline[j].flag & mark))
523+
sline[j].flag |= no_pre_delete;
524+
sline[j++].flag |= mark;
525+
}
523526

524527
again:
525528
/* we know up to i is to be included. where does the

t/t4038-diff-combined.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,52 @@ test_expect_failure 'combine diff coalesce three parents' '
353353
compare_diff_patch expected actual
354354
'
355355

356+
# Test for a bug reported at
357+
# http://thread.gmane.org/gmane.comp.version-control.git/224410
358+
# where a delete lines were missing from combined diff output when they
359+
# occurred exactly before the context lines of a later change.
360+
test_expect_success 'combine diff missing delete bug' '
361+
git commit -m initial --allow-empty &&
362+
cat <<-\EOF >test &&
363+
1
364+
2
365+
3
366+
4
367+
EOF
368+
git add test &&
369+
git commit -a -m side1 &&
370+
git checkout -B side1 &&
371+
git checkout HEAD^ &&
372+
cat <<-\EOF >test &&
373+
0
374+
1
375+
2
376+
3
377+
4modified
378+
EOF
379+
git add test &&
380+
git commit -m side2 &&
381+
git branch -f side2 &&
382+
test_must_fail git merge --no-commit side1 &&
383+
cat <<-\EOF >test &&
384+
1
385+
2
386+
3
387+
4modified
388+
EOF
389+
git add test &&
390+
git commit -a -m merge &&
391+
git diff-tree -c -p HEAD >actual.tmp &&
392+
sed -e "1,/^@@@/d" < actual.tmp >actual &&
393+
tr -d Q <<-\EOF >expected &&
394+
- 0
395+
1
396+
2
397+
3
398+
-4
399+
+4modified
400+
EOF
401+
compare_diff_patch expected actual
402+
'
403+
356404
test_done

0 commit comments

Comments
 (0)