commit - ac2eeeffef0b2071f39513685c4b6d594a30416d
commit + 44cf49504c18b4bb2edd3518b6e1192b5e4f4416
blob - 79fe3c4b8682eaf5665b62bb3c1e6d8ebb7bc745
blob + 60517c0a36ecf3978e948dc526f31cae3892f0b2
--- lib/diff_patience.c
+++ lib/diff_patience.c
#include "debug.h"
/* Set unique_here = true for all atoms that exist exactly once in this list. */
-static void
+static int
diff_atoms_mark_unique(struct diff_data *d, unsigned int *unique_count)
{
struct diff_atom *i;
bool same;
int r = diff_atom_same(&same, i, j);
if (r)
- abort(); // TODO: error handling
+ return r;
if (!same)
continue;
if (i->patience.unique_here) {
}
if (unique_count)
*unique_count = count;
+ return 0;
}
/* Mark those lines as atom->patience.unique_in_both = true that appear exactly
* once in each side. */
-static void
+static int
diff_atoms_mark_unique_in_both(struct diff_data *left, struct diff_data *right,
unsigned int *unique_in_both_count)
{
* iteration. So this is just some optimiziation to save one iteration
* in the end. */
unsigned int unique_in_both;
+ int r;
- diff_atoms_mark_unique(left, &unique_in_both);
- diff_atoms_mark_unique(right, NULL);
+ r = diff_atoms_mark_unique(left, &unique_in_both);
+ if (r)
+ return r;
+ r = diff_atoms_mark_unique(right, NULL);
+ if (r)
+ return r;
debug("unique_in_both %u\n", unique_in_both);
bool same;
int r = diff_atom_same(&same, i, j);
if (r)
- abort(); // TODO: error handling
+ return r;
if (!same)
continue;
if (!j->patience.unique_here) {
continue;
r = diff_atom_same(&same, i, j);
if (r)
- abort(); // TODO: error handling
+ return r;
if (!same)
continue;
found_in_a = true;
if (unique_in_both_count)
*unique_in_both_count = unique_in_both;
+ return 0;
}
-static void
+static int
diff_atoms_swallow_identical_neighbors(struct diff_data *left,
struct diff_data *right,
unsigned int *unique_in_both_count)
&left->atoms.head[identical_l.start - 1],
&right->atoms.head[identical_r.start - 1]);
if (r)
- abort(); // TODO: error handling
+ return r;
if (!same)
break;
}
&left->atoms.head[identical_l.end],
&right->atoms.head[identical_r.end]);
if (r)
- abort(); // TODO: error handling
+ return r;
if (!same)
break;
l_end = &left->atoms.head[identical_l.end];
}
debug("next_l_idx = %u\n", next_l_idx);
}
+ return 0;
}
/* binary search to find the stack to put this atom "card" on. */
diff_algo_patience(const struct diff_algo_config *algo_config,
struct diff_state *state)
{
- int rc = ENOMEM;
+ int rc;
struct diff_data *left = &state->left;
struct diff_data *right = &state->right;
/* Find those lines that appear exactly once in 'left' and exactly once
* in 'right'. */
- diff_atoms_mark_unique_in_both(left, right, &unique_in_both_count);
+ rc = diff_atoms_mark_unique_in_both(left, right, &unique_in_both_count);
+ if (rc)
+ return rc;
debug("unique_in_both_count %u\n", unique_in_both_count);
debug("left:\n");
return DIFF_RC_USE_DIFF_ALGO_FALLBACK;
}
- diff_atoms_swallow_identical_neighbors(left, right,
- &unique_in_both_count);
+ rc = diff_atoms_swallow_identical_neighbors(left, right,
+ &unique_in_both_count);
+ if (rc)
+ return rc;
debug("After swallowing identical neighbors: unique_in_both = %u\n",
unique_in_both_count);
+ rc = ENOMEM;
+
/* An array of Longest Common Sequence is the result of the below
* subscope: */
unsigned int lcs_count = 0;