Commit Diff


commit - 2c12b171fbb19e2b5423c046fbb9cb86b60632eb
commit + 65688edf4c58356b6a78c043dae1a4832532b84f
blob - 90e4bb8ef6330a66994c94fc1ecbd104f42a3846
blob + c7951fc286a8aaf1ecc4c6330827f27d18c6dea4
--- lib/diff_patience.c
+++ lib/diff_patience.c
@@ -51,13 +51,19 @@ int diff_atoms_qsort_compar(const void *_a, const void
 	const struct diff_atom *a = *(struct diff_atom**)_a;
 	const struct diff_atom *b = *(struct diff_atom**)_b;
 	int cmp;
-	int rc;
+	int rc = 0;
 
-	if (a->root->err || b->root->err) {
-		/* If atoms are from more than one diff_data, make sure the
-		 * error, if any, spreads to all of them. */
+	/* If there's been an error (e.g. I/O error) in a previous compar, we have no way to abort the qsort but just
+	 * report the rc and stop comparing. Make sure to catch errors on either side. If atoms are from more than one
+	 * diff_data, make sure the error, if any, spreads to all of them, so we can cut short all future compar. */
+	if (a->root->err)
+		rc = a->root->err;
+	if (b->root->err)
+		rc = b->root->err;
+	if (rc) {
 		a->root->err = rc;
 		b->root->err = rc;
+		/* just return 'equal' to not swap more positions */
 		return 0;
 	}