teach diff machinery about --ignore-space-at-eol
`git diff --ignore-space-at-eol` will ignore whitespace at the line ends. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Feb 14, 2007 at 01:30 UTC
859f9c45814afae3250424946e2156ea366224f7
3 files changed
+28
-1
diff.c
+2
@@ -2038,6 +2038,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
2038
options->xdl_opts |= XDF_IGNORE_WHITESPACE;
2039
else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
2040
options->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
2041
+ else if (!strcmp(arg, "--ignore-space-at-eol"))
2042
+ options->xdl_opts |= XDF_IGNORE_WHITESPACE_AT_EOL;
2043
else if (!strcmp(arg, "--color-words"))
2044
options->color_diff = options->color_diff_words = 1;
2045
else if (!strcmp(arg, "--no-renames"))
xdiff/xdiff.h
+2
-1
@@ -31,7 +31,8 @@ extern "C" {
31
#define XDF_NEED_MINIMAL (1 << 1)
32
#define XDF_IGNORE_WHITESPACE (1 << 2)
33
#define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
34
-#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)
34
+#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
35
+#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
36
37
#define XDL_PATCH_NORMAL '-'
38
#define XDL_PATCH_REVERSE '+'
xdiff/xutils.c
+24
@@ -215,6 +215,21 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
215
return 0;
216
}
217
return (i1 >= s1 && i2 >= s2);
218
+ } else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {
219
+ for (i1 = i2 = 0; i1 < s1 && i2 < s2; ) {
220
+ if (l1[i1] != l2[i2]) {
221
+ while (i1 < s1 && isspace(l1[i1]))
222
+ i1++;
223
+ while (i2 < s2 && isspace(l2[i2]))
224
+ i2++;
225
+ if (i1 < s1 || i2 < s2)
226
+ return 0;
227
+ return 1;
228
+ }
229
+ i1++;
230
+ i2++;
231
+ }
232
+ return i1 >= s1 && i2 >= s2;
233
} else
234
return s1 == s2 && !memcmp(l1, l2, s1);
235
@@ -227,6 +242,7 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
242
243
for (; ptr < top && *ptr != '\n'; ptr++) {
244
if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {
245
+ const char *ptr2 = ptr;
246
while (ptr + 1 < top && isspace(ptr[1])
247
&& ptr[1] != '\n')
248
ptr++;
@@ -235,6 +251,14 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
251
ha += (ha << 5);
252
ha ^= (unsigned long) ' ';
253
}
254
+ if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
255
+ && ptr[1] != '\n') {
256
+ while (ptr2 != ptr + 1) {
257
+ ha += (ha << 5);
258
+ ha ^= (unsigned long) *ptr2;
259
+ ptr2++;
260
+ }
261
+ }
262
continue;
263
}
264
ha += (ha << 5);