Commit Diff


commit - d1085492979de6b79ca99fd96cbbb5799a83aa82
commit + ab378e1f5dfdd34727e7eb8a2ccb8c6d42bc6e89
blob - 71371779dde10d2eea855d4434f62c2b74b4e87b
blob + 6fcac654d42e60add575f4927506202f226e0ea3
--- lib/diff_patience.c
+++ lib/diff_patience.c
@@ -652,6 +652,7 @@ diff_algo_patience(const struct diff_algo_config *algo
 		 * [left_idx..identical_lines.end[. */
 		unsigned int left_idx;
 		unsigned int right_idx;
+		int already_done_count = 0;
 
 		debug("iteration %u of %u  left_pos %u  right_pos %u\n",
 		      i, lcs_count, left_pos, right_pos);
@@ -681,7 +682,7 @@ diff_algo_patience(const struct diff_algo_config *algo
 			 * consuming the same identical atoms around a pair of
 			 * common-unique atoms more than once.
 			 * See also marker the other place marked with (1). */
-			int already_done_count = right_pos - right_idx;
+			already_done_count = right_pos - right_idx;
 			left_idx += already_done_count;
 			right_idx += already_done_count;
 			/* Paranoia: make sure we're skipping just an
@@ -743,13 +744,19 @@ diff_algo_patience(const struct diff_algo_config *algo
 		 * lines. */
 		if (atom) {
 			void *ok;
+			unsigned int left_start = PATIENCE(atom).identical_lines.start;
+			unsigned int left_len = diff_range_len(&PATIENCE(atom).identical_lines);
+			unsigned int right_start = PATIENCE(atom_r).identical_lines.start;
+			unsigned int right_len = diff_range_len(&PATIENCE(atom_r).identical_lines);
+
+			left_start += already_done_count;
+			left_len -= already_done_count;
+			right_start += already_done_count;
+			right_len -= already_done_count;
+
 			ok = diff_state_add_chunk(state, true,
-				left->atoms.head
-				    + PATIENCE(atom).identical_lines.start,
-				diff_range_len(&PATIENCE(atom).identical_lines),
-				right->atoms.head
-				    + PATIENCE(atom_r).identical_lines.start,
-				diff_range_len(&PATIENCE(atom_r).identical_lines));
+				left->atoms.head + left_start, left_len,
+				right->atoms.head + right_start, right_len);
 			if (!ok)
 				goto free_and_exit;
 			left_pos = PATIENCE(atom).identical_lines.end;