Commit Diff


commit - 1c7f8717f7d2453699badd65470c3990e8eb5585
commit + 845f35754a8e7935c62f11f48d5dedd536a0615c
blob - 5a2a8bda750380fb1efff14025971d22cad8d274
blob + 03081043814bb567b617b3838d6eef93db8052c1
--- lib/diff_atomize_text.c
+++ lib/diff_atomize_text.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #include <arraylist.h>
 #include <diff_main.h>
@@ -35,6 +36,7 @@ diff_data_atomize_text_lines_fd(struct diff_data *d)
 	const off_t end = pos + d->len;
 	unsigned int array_size_estimate = d->len / 50;
 	unsigned int pow2 = 1;
+	bool ignore_whitespace = (d->diff_flags & DIFF_FLAG_IGNORE_WHITESPACE);
 
 	while (array_size_estimate >>= 1)
 		pow2++;
@@ -59,7 +61,9 @@ diff_data_atomize_text_lines_fd(struct diff_data *d)
 			i = 0;
 			while (eol == 0 && i < r) {
 				if (buf[i] != '\r' && buf[i] != '\n') {
-					hash = hash * 23 + buf[i];
+					if (!ignore_whitespace
+					    || !isspace(buf[i]))
+						hash = hash * 23 + buf[i];
 					line_end++;
 				} else
 					eol = buf[i];
@@ -109,6 +113,7 @@ diff_data_atomize_text_lines_mmap(struct diff_data *d)
 {
 	const uint8_t *pos = d->data;
 	const uint8_t *end = pos + d->len;
+	bool ignore_whitespace = (d->diff_flags & DIFF_FLAG_IGNORE_WHITESPACE);
 
 	unsigned int array_size_estimate = d->len / 50;
 	unsigned int pow2 = 1;
@@ -122,7 +127,9 @@ diff_data_atomize_text_lines_mmap(struct diff_data *d)
 		unsigned int hash = 0;
 
 		while (line_end < end && *line_end != '\r' && *line_end != '\n') {
-			hash = hash * 23 + *line_end;
+			if (!ignore_whitespace
+			    || !isspace(*line_end))
+				hash = hash * 23 + *line_end;
 			line_end++;
 		}