From 404c3283cb0b4d0244df5adb0199e9fb9ff9988c Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 7 Jun 2011 11:02:11 -0700 Subject: [PATCH] Don't ignore internal whitespace changes in "Whitespace: Ignore All" Summary: When whitespace changes between two non-whitespace characters (e.g., in a string), always treat it as a change. Test Plan: Disabled render cache, made internal and external whitespace changes, rendered a diff, got internal change always marked and external change marked correctly depending on mode. Reviewed By: tuomaspelkonen Reviewers: tuomaspelkonen CC: aran, tuomaspelkonen, epriestley Differential Revision: 403 --- .../changeset/DifferentialChangesetParser.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php index abcf37868a..e4bd9cde87 100644 --- a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php @@ -404,6 +404,26 @@ class DifferentialChangesetParser { continue; } $new[$k]['text'] = idx($new_text, $desc['line']); + + // If there's a corresponding "old" text and the line is marked as + // unchanged, test if there are internal whitespace changes between + // non-whitespace characters, e.g. spaces added to a string or spaces + // added around operators. If we find internal spaces, mark the line + // as changed. + // + // We only need to do this for "new" lines because any line that is + // missing either "old" or "new" text certainly can not have internal + // whitespace changes without also having non-whitespace changes, + // because characters had to be either added or removed to create the + // possibility of internal whitespace. + if (isset($old[$k]['text']) && empty($new[$k]['type'])) { + if (trim($old[$k]['text']) != trim($new[$k]['text'])) { + // The strings aren't the same when trimmed, so there are internal + // whitespace changes. Mark this line changed. + $old[$k]['type'] = '-'; + $new[$k]['type'] = '+'; + } + } } $this->old = $old; @@ -725,7 +745,7 @@ class DifferentialChangesetParser { Filesystem::writeFile($old_tmp, $changeset->makeOldFile()); Filesystem::writeFile($new_tmp, $changeset->makeNewFile()); list($err, $diff) = exec_manual( - 'diff -bw -U65535 %s %s', + 'diff -bw -U65535 %s %s ', $old_tmp, $new_tmp);