Allow DifferentialDiff to construct proper DifferentialChangeset objects from
diffs which add empty files Summary: See T507 and some others. We now parse empty git diffs correctly, but the logic to build DifferentialDiffs out of them leaves the objects with 'null' for $changesets, when it should be array(). Further layers later throw, believing we have not loaded the changesets, when we actually have, there just aren't any. Test Plan: Viewed rJX05d493e17fbbb29f29e4880be6834d1d7415374e in Diffusion, which adds an empty README file. No exception thrown. Reviewers: jungejason, nh, tuomaspelkonen, aran Reviewed By: nh CC: aran, nh Differential Revision: 1038
This commit is contained in:
@@ -114,7 +114,9 @@ class DifferentialDiff extends DifferentialDAO {
|
|||||||
$changeset = new DifferentialChangeset();
|
$changeset = new DifferentialChangeset();
|
||||||
$add_lines = 0;
|
$add_lines = 0;
|
||||||
$del_lines = 0;
|
$del_lines = 0;
|
||||||
foreach ($change->getHunks() as $hunk) {
|
$hunks = $change->getHunks();
|
||||||
|
if ($hunks) {
|
||||||
|
foreach ($hunks as $hunk) {
|
||||||
$dhunk = new DifferentialHunk();
|
$dhunk = new DifferentialHunk();
|
||||||
$dhunk->setOldOffset($hunk->getOldOffset());
|
$dhunk->setOldOffset($hunk->getOldOffset());
|
||||||
$dhunk->setOldLen($hunk->getOldLength());
|
$dhunk->setOldLen($hunk->getOldLength());
|
||||||
@@ -126,6 +128,10 @@ class DifferentialDiff extends DifferentialDAO {
|
|||||||
$del_lines += $hunk->getDelLines();
|
$del_lines += $hunk->getDelLines();
|
||||||
$lines += $add_lines + $del_lines;
|
$lines += $add_lines + $del_lines;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// This happens when you add empty files.
|
||||||
|
$changeset->attachHunks(array());
|
||||||
|
}
|
||||||
|
|
||||||
$changeset->setOldFile($change->getOldPath());
|
$changeset->setOldFile($change->getOldPath());
|
||||||
$changeset->setFilename($change->getCurrentPath());
|
$changeset->setFilename($change->getCurrentPath());
|
||||||
|
|||||||
Reference in New Issue
Block a user