[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] new option --ignore-trailing-space-change for diff
From: |
Roland McGrath |
Subject: |
[PATCH] new option --ignore-trailing-space-change for diff |
Date: |
Wed, 30 Jun 2004 20:15:02 -0700 |
This is relative to diffutils-2.8.7 and all in the src/ directory.
This patch adds --ignore-trailing-space-change, short option -z. This is
similar to -b, but ignores only trailing white space. I find this is
always what I want for making diffs of code. Changes in trailing white
space are uninteresting (and sometimes automatic, e.g. whitespace.el),
while changes in leading or internal white space on a line are meaningful
code formatting changes.
This works for the real world cases I've tried today. I haven't given it
any exhaustive testing. I am not really sure about some of the tests done
on ignore_white_space in analyze_hunk and find_and_hash_each_line, which do
magically different things depending on < or > IGNORE_WHITE_SPACE. I don't
understand what those do, so I don't really know on which side of those
IGNORE_TRAILING_SPACE_CHANGE ought to land. Also, I made this another
ignore_white_space enum value since that seemed consistent with what's
there now. But in fact -z could be orthogonal to -E and one might very
well want to use both. If I understood those ordering comparisons used on
it, I might understand why they are a little spectrum of one value instead
of individual switches.
If there is anything I can change that will convince you to put this into
diff, please let me know.
Thanks,
Roland
2004-06-30 Roland McGrath <address@hidden>
* src/diff.c (shortopts, longopts, main, option_help_msgid): Add
-z/--ignore-trailing-space-change option.
* src/diff.h: Add IGNORE_TRAILING_SPACE_CHANGE enum value.
* src/util.c (lines_differ): Handle IGNORE_TRAILING_SPACE_CHANGE.
* src/io.c (find_and_hash_each_line): Likewise.
--- diff.c.~1~ 2004-04-12 00:44:35.000000000 -0700
+++ diff.c 2004-06-30 19:24:24.000000000 -0700
@@ -137,7 +137,7 @@ exclude_options (void)
}
static char const shortopts[] =
-"0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:y";
+"0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:yz";
/* Values for long options that do not have single-letter equivalents. */
enum
@@ -206,6 +206,7 @@ static struct option const longopts[] =
{"ignore-file-name-case", 0, 0, IGNORE_FILE_NAME_CASE_OPTION},
{"ignore-matching-lines", 1, 0, 'I'},
{"ignore-space-change", 0, 0, 'b'},
+ {"ignore-trailing-space-change", 0, 0, 'z'},
{"ignore-tab-expansion", 0, 0, 'E'},
{"inhibit-hunk-merge", 0, 0, INHIBIT_HUNK_MERGE_OPTION},
{"initial-tab", 0, 0, 'T'},
@@ -308,6 +309,11 @@ main (int argc, char **argv)
ignore_white_space = IGNORE_SPACE_CHANGE;
break;
+ case 'z':
+ if (ignore_white_space < IGNORE_TRAILING_SPACE_CHANGE)
+ ignore_white_space = IGNORE_TRAILING_SPACE_CHANGE;
+ break;
+
case 'B':
ignore_blank_lines = true;
break;
@@ -859,6 +865,7 @@ static char const * const option_help_ms
N_("--no-ignore-file-name-case Consider case when comparing file names."),
N_("-E --ignore-tab-expansion Ignore changes due to tab expansion."),
N_("-b --ignore-space-change Ignore changes in the amount of white
space."),
+ N_("-z --ignore-trailing-space-change Ignore changes in the amount of
white space at the end of a line."),
N_("-w --ignore-all-space Ignore all white space."),
N_("-B --ignore-blank-lines Ignore changes whose lines are all blank."),
N_("-I RE --ignore-matching-lines=RE Ignore changes whose lines all match
RE."),
--- diff.h.~1~ 2004-04-12 00:44:35.000000000 -0700
+++ diff.h 2004-06-30 19:40:04.000000000 -0700
@@ -108,6 +108,9 @@ XTERN enum
/* Ignore changes due to tab expansion (-E). */
IGNORE_TAB_EXPANSION,
+ /* Ignore changes in trailing horizontal white space (-z). */
+ IGNORE_TRAILING_SPACE_CHANGE,
+
/* Ignore changes in horizontal white space (-b). */
IGNORE_SPACE_CHANGE,
--- io.c.~1~ 2004-04-12 00:44:35.000000000 -0700
+++ io.c 2004-06-30 19:48:42.000000000 -0700
@@ -254,6 +254,26 @@ find_and_hash_each_line (struct file_dat
h = HASH (h, tolower (c));
break;
+ case IGNORE_TRAILING_SPACE_CHANGE:
+ while ((c = *p++) != '\n')
+ {
+ if (isspace (c))
+ {
+ /* Check if the rest of the line is all white space. */
+ char const *q = p;
+ while (*q != '\n' && isspace ((unsigned char) *q))
+ ++q;
+ if (*q == '\n')
+ {
+ /* Ignore all the trailing white space. */
+ p = q + 1;
+ goto hashing_done;
+ }
+ }
+ h = HASH (h, tolower (c));
+ }
+ break;
+
case IGNORE_SPACE_CHANGE:
while ((c = *p++) != '\n')
{
@@ -324,6 +344,26 @@ find_and_hash_each_line (struct file_dat
h = HASH (h, c);
break;
+ case IGNORE_TRAILING_SPACE_CHANGE:
+ while ((c = *p++) != '\n')
+ {
+ if (isspace (c))
+ {
+ /* Check if the rest of the line is all white space. */
+ char const *q = p;
+ while (*q != '\n' && isspace ((unsigned char) *q))
+ ++q;
+ if (*q == '\n')
+ {
+ /* Ignore all the trailing white space. */
+ p = q + 1;
+ goto hashing_done;
+ }
+ }
+ h = HASH (h, c);
+ }
+ break;
+
case IGNORE_SPACE_CHANGE:
while ((c = *p++) != '\n')
{
--- util.c.~1~ 2004-04-12 00:44:35.000000000 -0700
+++ util.c 2004-06-30 20:01:33.000000000 -0700
@@ -341,6 +341,31 @@ lines_differ (char const *s1, char const
while (isspace (c2) && c2 != '\n') c2 = *t2++;
break;
+ case IGNORE_TRAILING_SPACE_CHANGE:
+ if (isspace (c1) && isspace (c2))
+ {
+ register char const *p;
+ if (c1 != '\n')
+ {
+ p = t1;
+ while (*p != '\n' && isspace ((unsigned char) *p))
+ ++p;
+ if (*p != '\n')
+ break;
+ }
+ if (c2 != '\n')
+ {
+ p = t2;
+ while (*p != '\n' && isspace ((unsigned char) *p))
+ ++p;
+ if (*p != '\n')
+ break;
+ }
+ /* Both lines have nothing but whitespace left. */
+ return false;
+ }
+ break;
+
case IGNORE_SPACE_CHANGE:
/* For -b, advance past any sequence of white space in
line 1 and consider it just one space, or nothing at
- [PATCH] new option --ignore-trailing-space-change for diff,
Roland McGrath <=