ref: b61ca21ef5e741a68439c84e9f8c79f690215375
parent: 14806f5a6b9c28df86a14e726260520c733faa17
author: Ori Bernstein <[email protected]>
date: Sun Feb 12 17:56:13 EST 2023
merge3: align edges of chunks
--- a/merge3.c
+++ b/merge3.c
@@ -63,7 +63,7 @@
char*
merge(Diff *l, Diff *r)
{
- int il, ir, a, b;
+ int il, ir, a, b, δ;
Change *lc, *rc;
vlong ln;
@@ -78,10 +78,33 @@
if(il < l->nchanges)
lc = &l->changes[il];
if(ir < r->nchanges)
- rc = &r->changes[il];
+ rc = &r->changes[ir];
if(overlaps(lc, rc)){
- a = (lc->a < rc->a) ? lc->a : rc->a;
- b = (lc->b > rc->b) ? lc->b : rc->b;
+ /*
+ * align the edges of the chunks
+ */
+ if(lc->a < rc->a){
+ a = lc->a;
+ δ = rc->a - lc->a;
+ rc->a -= δ;
+ rc->c -= δ;
+ }else{
+ a = rc->a;
+ δ = lc->a - rc->a;
+ lc->a -= δ;
+ lc->c -= δ;
+ }
+ if(lc->b > rc->b){
+ b = lc->b;
+ δ = lc->b - rc->b;
+ rc->b += δ;
+ rc->d += δ;
+ }else{
+ b = rc->b;
+ δ = rc->b - lc->b;
+ rc->b += δ;
+ rc->d += δ;
+ }
fetch(l, l->ixold, ln, a-1, l->input[0], "");
Bprint(&stdout, "<<<<<<<<<< %s\n", l->file2);
fetch(l, l->ixnew, lc->c, lc->d, l->input[1], "");