From 1d9d2d066e222510e54e4d3631eb056ee16e67be Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 22 Apr 2020 20:20:00 -0700 Subject: [PATCH] (stable) Don't pass "No newline at end of file." annotations to DocumentEngines as literal diff text Summary: See PHI1707, which has a Jupyter notebook which fails to diff nicely when modified. The root cause seems to be that the document does not end in a newline. Test Plan: Applied patch, diffed the file, got a Jupyter diff out of it. Differential Revision: https://secure.phabricator.com/D21159 --- .../parser/DifferentialChangesetParser.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 92d5f23c1a..dc6d17acc3 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -1701,10 +1701,7 @@ final class DifferentialChangesetParser extends Phobject { if ($old_file) { $old_ref->setFile($old_file); } else { - $old_data = $this->old; - $old_data = ipull($old_data, 'text'); - $old_data = implode('', $old_data); - + $old_data = $this->getRawDocumentEngineData($this->old); $old_ref->setData($old_data); } } @@ -1717,10 +1714,7 @@ final class DifferentialChangesetParser extends Phobject { if ($new_file) { $new_ref->setFile($new_file); } else { - $new_data = $this->new; - $new_data = ipull($new_data, 'text'); - $new_data = implode('', $new_data); - + $new_data = $this->getRawDocumentEngineData($this->new); $new_ref->setData($new_data); } } @@ -1860,4 +1854,20 @@ final class DifferentialChangesetParser extends Phobject { return array($old_file, $new_file); } + private function getRawDocumentEngineData(array $lines) { + $text = array(); + + foreach ($lines as $line) { + // If this is a "No newline at end of file." annotation, don't hand it + // off to the DocumentEngine. + if ($line['type'] == '\\') { + continue; + } + + $text[] = $line['text']; + } + + return implode('', $text); + } + }