Commit Diff


commit - 8ac34c07fc49677851335001051426eeb7fed1b0
commit + bb867e685c9179eca1eb5b49c9a09b6e837baa28
blob - 2f436da2ef8207a4c86d757974d9937918bea73e
blob + d36fb854afc9ab22a89de3c5b8033bf0f42de3f3
--- lib/diff_main.c
+++ lib/diff_main.c
@@ -229,6 +229,12 @@ diff_state_add_chunk(struct diff_state *state, bool so
 	enum diff_chunk_type last_t;
 	enum diff_chunk_type prev_last_t;
 	enum diff_chunk_type new_t;
+
+	debug("Add %s chunk:\n", chunk.solved ? "solved" : "UNSOLVED");
+	debug("L\n");
+	debug_dump_atoms(&state->left, chunk.left_start, chunk.left_count);
+	debug("R\n");
+	debug_dump_atoms(&state->right, chunk.right_start, chunk.right_count);
 
 	if (!solved || state->temp_result.len) {
 		/* Append to temp_result */
@@ -258,6 +264,11 @@ diff_state_add_chunk(struct diff_state *state, bool so
 		new_chunk = &result->head[result->len - 1];
 		new_chunk->left_count += chunk.left_count;
 		new_chunk->right_count += chunk.right_count;
+		debug("  - added chunk touches previous one of same type, joined:\n");
+		debug("L\n");
+		debug_dump_atoms(&state->left, new_chunk->left_start, new_chunk->left_count);
+		debug("R\n");
+		debug_dump_atoms(&state->right, new_chunk->right_start, new_chunk->right_count);
 	} else if (last_t == CHUNK_PLUS && new_t == CHUNK_MINUS) {
 		/* If a minus-chunk follows a plus-chunk, place it above the plus-chunk.
 		 * Is the one before that also a minus? combine. */
@@ -265,11 +276,22 @@ diff_state_add_chunk(struct diff_state *state, bool so
 			new_chunk = &result->head[result->len - 2];
 			new_chunk->left_count += chunk.left_count;
 			new_chunk->right_count += chunk.right_count;
+
+			debug("  - added minus-chunk follows plus-chunk,"
+			      " put before that plus-chunk and joined"
+			      " with preceding minus-chunk:\n");
+			debug("L\n");
+			debug_dump_atoms(&state->left, new_chunk->left_start, new_chunk->left_count);
+			debug("R\n");
+			debug_dump_atoms(&state->right, new_chunk->right_start, new_chunk->right_count);
 		} else {
 			ARRAYLIST_INSERT(new_chunk, *result, result->len - 2);
 			if (!new_chunk)
 				return NULL;
 			*new_chunk = chunk;
+
+			debug("  - added minus-chunk follows plus-chunk,"
+			      " put before that plus-chunk\n");
 		}
 	} else {
 		ARRAYLIST_ADD(new_chunk, *result);
@@ -280,11 +302,6 @@ diff_state_add_chunk(struct diff_state *state, bool so
 	}
 
 chunk_added:
-	debug("Add %s chunk:\n", new_chunk->solved ? "solved" : "UNSOLVED");
-	debug("L\n");
-	debug_dump_atoms(&state->left, new_chunk->left_start, new_chunk->left_count);
-	debug("R\n");
-	debug_dump_atoms(&state->right, new_chunk->right_start, new_chunk->right_count);
 	return new_chunk;
 }