1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 22:10:54 +01:00

Correctly parse git diffs with an empty file at the end

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
This commit is contained in:
epriestley 2011-10-10 12:34:28 -07:00
parent 2fd37a1728
commit 1da98a11f1
19 changed files with 17 additions and 1 deletions

View 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();
}
}

View 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);

View file

View file

View file

0
src/parser/diff/__tests__/data/git-commit.gitdiff Executable file → Normal file
View file

0
src/parser/diff/__tests__/data/git-copy-plus.gitdiff Executable file → Normal file
View file

0
src/parser/diff/__tests__/data/git-copy.gitdiff Executable file → Normal file
View file

0
src/parser/diff/__tests__/data/git-delete-file.gitdiff Executable file → Normal file
View file

View file

@ -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

View file

View file

0
src/parser/diff/__tests__/data/git-move-edit.gitdiff Executable file → Normal file
View file

0
src/parser/diff/__tests__/data/git-move-plus.gitdiff Executable file → Normal file
View file

0
src/parser/diff/__tests__/data/git-move.gitdiff Executable file → Normal file
View file

0
src/parser/diff/__tests__/data/svn-binary-diff.svndiff Executable file → Normal file
View file

View file

View file

View file