[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: diffutils 2.8: newlines not ignored under -w
From: |
Paul Eggert |
Subject: |
Re: diffutils 2.8: newlines not ignored under -w |
Date: |
Fri, 5 Apr 2002 23:14:28 -0800 (PST) |
> From: "Robert A. (Bob) Morris" <address@hidden>
> Date: Fri, 5 Apr 2002 23:40:58 -0500
>
> If the difference is solely a line with nothing but whitespace
> containing /more/ than just a newline, diff -wB reports a difference,
> as does Solaris diff.
That is how -B is documented to behave. (Solaris diff doesn't have
-B, so the issue doesn't arise there.)
However, I agree that if -w or -b is specified, then -B should ignore
changes consisting entirely of lines containing only white space.
Here's a patch to do that -- could you please try it out?
This patch is relative to GNU Diffutils 2.8.1, which you can get from:
<ftp://ftp.gnu.org/gnu/diffutils/diffutils-2.8.1.tar.gz>
(There also needs to be a change to the documentation.)
===================================================================
RCS file: src/RCS/util.c,v
retrieving revision 1.31
diff -pu -r1.31 src/util.c
--- src/util.c 2002/02/28 05:22:26 1.31
+++ src/util.c 2002/04/06 06:59:52
@@ -655,6 +655,8 @@ analyze_hunk (struct change *hunk,
size_t trivial_length = (int) ignore_blank_lines - 1;
/* If 0, ignore zero-length lines;
if SIZE_MAX, do not ignore lines just because of their length. */
+ bool skip_leading_white_space =
+ (ignore_blank_lines && IGNORE_SPACE_CHANGE <= ignore_white_space);
char const * const *linbuf0 = files[0].linbuf; /* Help the compiler. */
char const * const *linbuf1 = files[1].linbuf;
@@ -675,8 +677,13 @@ analyze_hunk (struct change *hunk,
for (i = next->line0; i <= l0 && trivial; i++)
{
char const *line = linbuf0[i];
- size_t len = linbuf0[i + 1] - line - 1;
- if (len != trivial_length
+ char const *newline = linbuf0[i + 1] - 1;
+ size_t len = newline - line;
+ char const *p = line;
+ if (skip_leading_white_space)
+ while (ISSPACE ((unsigned char) *p) && *p != '\n')
+ p++;
+ if (newline - p != trivial_length
&& (! ignore_regexp.fastmap
|| re_search (&ignore_regexp, line, len, 0, len, 0) < 0))
trivial = 0;
@@ -685,8 +692,13 @@ analyze_hunk (struct change *hunk,
for (i = next->line1; i <= l1 && trivial; i++)
{
char const *line = linbuf1[i];
- size_t len = linbuf1[i + 1] - line - 1;
- if (len != trivial_length
+ char const *newline = linbuf1[i + 1] - 1;
+ size_t len = newline - line;
+ char const *p = line;
+ if (skip_leading_white_space)
+ while (ISSPACE ((unsigned char) *p) && *p != '\n')
+ p++;
+ if (newline - p != trivial_length
&& (! ignore_regexp.fastmap
|| re_search (&ignore_regexp, line, len, 0, len, 0) < 0))
trivial = 0;