]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Correctly parse git diffs with an empty file at the end
authorepriestley <git@epriestley.com>
Mon, 10 Oct 2011 19:34:28 +0000 (12:34 -0700)
committerepriestley <git@epriestley.com>
Tue, 11 Oct 2011 02:03:48 +0000 (19:03 -0700)
Summary: A minor bug in the parser prevented it from handling git diffs where an
empty file appears at the end of the diff. Since git appends an extra newline,
we failed to jump into the '$line === null' block.

Test Plan: Ran unit tests. Generated a revision which only deleted an empty
file.

Reviewers: jungejason, nh, tuomaspelkonen, aran

Reviewed By: nh

CC: aran, nh, epriestley
Differential Revision: 998

19 files changed:
src/parser/diff/ArcanistDiffParser.php
src/parser/diff/__tests__/ArcanistDiffParserTestCase.php
src/parser/diff/__tests__/data/basic-missing-both-newlines-plus.udiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/basic-missing-new-newline-plus.udiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/basic-missing-old-newline-plus.udiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-commit.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-copy-plus.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-copy.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-delete-file.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-empty-files.gitdiff [new file with mode: 0644]
src/parser/diff/__tests__/data/git-ignore-whitespace-only.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-merge-header.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-move-edit.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-move-plus.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/git-move.gitdiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/svn-binary-diff.svndiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/svn-property-delete.svndiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/svn-property-merge.svndiff [changed mode: 0755->0644]
src/parser/diff/__tests__/data/svn-property-modify.svndiff [changed mode: 0755->0644]

index 28a7dd8353e49e32cb44085c41cd469768b6e335..dfd8fda940f8079db7174b2cb85f44ad3fee95e5 100644 (file)
@@ -569,7 +569,11 @@ class ArcanistDiffParser {
 
         // $this->didFailParse("Expected 'index af23f...a98bc' header line.");
       } else {
-        $line = $this->nextLine();
+        // NOTE: In the git case, where this patch is the last change in the
+        // file, we may have a final terminal newline. Skip over it so that
+        // we'll hit the '$line === null' block below. This is covered by the
+        // 'git-empty-file.gitdiff' test case.
+        $line = $this->nextNonemptyLine();
       }
     }
 
index b69ba362dd8cf5860fce74643dfded5015221d17..7e1fdc316b81eda504bf5f865ffedef36a08b60d 100644 (file)
@@ -412,6 +412,12 @@ EOTEXT
           $change->getNewProperties()
         );
         break;
+      case 'git-empty-files.gitdiff':
+        $this->assertEqual(2, count($changes));
+        while ($change = array_shift($changes)) {
+          $this->assertEqual(0, count($change->getHunks()));
+        }
+        break;
       case 'git-commit.gitdiff':
         $this->assertEqual(1, count($changes));
         $change = reset($changes);
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/src/parser/diff/__tests__/data/git-empty-files.gitdiff b/src/parser/diff/__tests__/data/git-empty-files.gitdiff
new file mode 100644 (file)
index 0000000..52cd5c3
--- /dev/null
@@ -0,0 +1,6 @@
+diff --git a/empty b/empty
+new file mode 100644
+index 0000000..e69de29
+diff --git a/empty2 b/empty2
+new file mode 100644
+index 0000000..e69de29
old mode 100755 (executable)
new mode 100644 (file)