commit - b3fb46867c2efc085c584bd336b9dca9cf26a161
commit + ac2eeeffef0b2071f39513685c4b6d594a30416d
blob - c164f2277b98e6aadeed4c94b4479e596473d531
blob + f56135e983c75dc1d4d176da40de71623e9d95b9
--- lib/diff_myers.c
+++ lib/diff_myers.c
* meeting_snake: resulting meeting point, if any.
* Return true when a meeting point has been identified.
*/
-static bool
-diff_divide_myers_forward(struct diff_data *left, struct diff_data *right,
+static int
+diff_divide_myers_forward(bool *found_midpoint,
+ struct diff_data *left, struct diff_data *right,
int *kd_forward, int *kd_backward, int d,
struct diff_box *meeting_snake)
{
int delta = (int)right->atoms.len - (int)left->atoms.len;
int k;
int x;
+ *found_midpoint = false;
debug("-- %s d=%d\n", __func__, d);
&left->atoms.head[x],
&right->atoms.head[
xk_to_y(x, k)]);
- if (r) {
- abort(); // TODO: error handling
- }
+ if (r)
+ return r;
if (!same)
break;
x++;
debug_dump_myers_graph(left, right, NULL,
kd_forward, d,
kd_backward, d-1);
- return true;
+ *found_midpoint = true;
+ return 0;
}
}
}
debug_dump_myers_graph(left, right, NULL, kd_forward, d,
kd_backward, d-1);
- return false;
+ return 0;
}
/* Do one backwards step in the "divide and conquer" graph traversal.
* meeting_snake: resulting meeting point, if any.
* Return true when a meeting point has been identified.
*/
-static bool
-diff_divide_myers_backward(struct diff_data *left, struct diff_data *right,
+static int
+diff_divide_myers_backward(bool *found_midpoint,
+ struct diff_data *left, struct diff_data *right,
int *kd_forward, int *kd_backward, int d,
struct diff_box *meeting_snake)
{
int delta = (int)right->atoms.len - (int)left->atoms.len;
int c;
int x;
+
+ *found_midpoint = false;
debug("-- %s d=%d\n", __func__, d);
&left->atoms.head[x-1],
&right->atoms.head[
xc_to_y(x, c, delta)-1]);
- if (r) {
- abort(); // TODO: error handling
- }
+ if (r)
+ return r;
if (!same)
break;
x--;
debug_dump_myers_graph(left, right, NULL,
kd_forward, d,
kd_backward, d);
- return true;
+ *found_midpoint = true;
+ return 0;
}
}
}
debug_dump_myers_graph(left, right, NULL, kd_forward, d, kd_backward,
d);
- return false;
+ return 0;
}
/* Myers "Divide et Impera": tracing forwards from the start and backwards from
struct diff_box mid_snake = {};
bool found_midpoint = false;
for (d = 0; d <= (max/2); d++) {
+ int r;
debug("-- d=%d\n", d);
- found_midpoint = diff_divide_myers_forward(left, right, kd_forward, kd_backward, d, &mid_snake);
+ r = diff_divide_myers_forward(&found_midpoint, left, right,
+ kd_forward, kd_backward, d,
+ &mid_snake);
+ if (r)
+ return r;
if (found_midpoint)
break;
- found_midpoint = diff_divide_myers_backward(left, right, kd_forward, kd_backward, d, &mid_snake);
+ r = diff_divide_myers_backward(&found_midpoint, left, right,
+ kd_forward, kd_backward, d,
+ &mid_snake);
+ if (r)
+ return r;
if (found_midpoint)
break;
}