diff --git a/sys/src/cmd/diff/merge3.c b/sys/src/cmd/diff/merge3.c index 2fd14c18d..f26f591f5 100644 --- a/sys/src/cmd/diff/merge3.c +++ b/sys/src/cmd/diff/merge3.c @@ -126,27 +126,25 @@ merge(Diff *l, Diff *r) * comparing same-sized chunks. */ if(lc->oldx < rc->oldx){ - x = lc->newx; δ = rc->oldx - lc->oldx; rc->oldx = max(rc->oldx-δ, 1); rc->newx = max(rc->newx-δ, 1); }else{ - x = rc->newx; δ = lc->oldx - rc->oldx; lc->oldx = max(lc->oldx-δ, 1); lc->newx = max(lc->newx-δ, 1); } if(lc->oldy > rc->oldy){ - y = lc->newy; δ = lc->oldy - rc->oldy; rc->oldy = min(rc->oldy+δ, r->len[0]); rc->newy = min(rc->newy+δ, r->len[1]); }else{ - y = rc->newy; δ = rc->oldy - lc->oldy; lc->oldy = min(lc->oldy+δ, l->len[0]); lc->newy = min(lc->newy+δ, l->len[1]); } + x = lc->oldx; + y = lc->oldy; if(same(l, lc, r, rc)){ fetch(l, l->ixold, ln, x-1, l->input[0], ""); fetch(l, l->ixnew, lc->newx, lc->newy, l->input[1], ""); @@ -161,7 +159,7 @@ merge(Diff *l, Diff *r) Bprint(&stdout, ">>>>>>>>>>\n"); status = "conflict"; } - ln = (y > x) ? y+1 : x+1; + ln = y+1; il++; ir++; }else if(lc != nil && (rc == nil || lx < rx)){ @@ -170,7 +168,7 @@ merge(Diff *l, Diff *r) ln = lc->oldy+1; il++; }else if(rc != nil && (lc == nil || rx < lx)){ - fetch(l, l->ixold, ln, rc->oldx-1, l->input[0], ""); + fetch(l, r->ixold, ln, rc->oldx-1, r->input[0], ""); fetch(r, r->ixnew, rc->newx, rc->newy, r->input[1], ""); ln = rc->oldy+1; ir++; diff --git a/sys/src/cmd/diff/test/merge-t13.c b/sys/src/cmd/diff/test/merge-t13.c new file mode 100644 index 000000000..689a0a62c --- /dev/null +++ b/sys/src/cmd/diff/test/merge-t13.c @@ -0,0 +1,19 @@ +1 + + + + + +10 +###1 +2 +3 +4 +y +6 +9 +ZZZZZZZZ + +9 +B +###0 diff --git a/sys/src/cmd/diff/test/merge-t13.expected b/sys/src/cmd/diff/test/merge-t13.expected new file mode 100644 index 000000000..89cfdd242 --- /dev/null +++ b/sys/src/cmd/diff/test/merge-t13.expected @@ -0,0 +1,28 @@ +1 +2 +3 +4 +x6 +7 +8 +9 + + + + + + + + + + + + +##3 +4 +5 +6 +7 +8 +9 +10 diff --git a/sys/src/cmd/diff/test/merge-t13.l b/sys/src/cmd/diff/test/merge-t13.l new file mode 100644 index 000000000..89cfdd242 --- /dev/null +++ b/sys/src/cmd/diff/test/merge-t13.l @@ -0,0 +1,28 @@ +1 +2 +3 +4 +x6 +7 +8 +9 + + + + + + + + + + + + +##3 +4 +5 +6 +7 +8 +9 +10 diff --git a/sys/src/cmd/diff/test/merge-t13.r b/sys/src/cmd/diff/test/merge-t13.r new file mode 100644 index 000000000..89cfdd242 --- /dev/null +++ b/sys/src/cmd/diff/test/merge-t13.r @@ -0,0 +1,28 @@ +1 +2 +3 +4 +x6 +7 +8 +9 + + + + + + + + + + + + +##3 +4 +5 +6 +7 +8 +9 +10 diff --git a/sys/src/cmd/diff/test/merge.rc b/sys/src/cmd/diff/test/merge.rc index 4ae0060c7..5eac3fd8e 100755 --- a/sys/src/cmd/diff/test/merge.rc +++ b/sys/src/cmd/diff/test/merge.rc @@ -1,6 +1,6 @@ #!/bin/rc -tests=`{seq 12} +tests=`{seq 13} for(t in $tests){ echo ../$O.merge3 merge-t$t.l merge-t$t.c merge-t$t.r ../$O.merge3 merge-t$t.l merge-t$t.c merge-t$t.r > merge-t$t.out