From be91064a1d0a1ac4104f9cc905a088edf6829120 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 21 Jan 2013 07:46:03 -0800 Subject: [PATCH] Fix Herald "any changed content" rule for commits Summary: Fixes T1330. This has been broken with a TODO since we open sourced. :/ Test Plan: Used test console to verify this produced the correct field value for several commits. Reviewers: btrahan, chad, vrana Reviewed By: chad CC: aran Maniphest Tasks: T1330 Differential Revision: https://secure.phabricator.com/D4563 --- .../herald/adapter/HeraldCommitAdapter.php | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php index b3dbf7ce46..5dee9ec0f6 100644 --- a/src/applications/herald/adapter/HeraldCommitAdapter.php +++ b/src/applications/herald/adapter/HeraldCommitAdapter.php @@ -103,6 +103,25 @@ final class HeraldCommitAdapter extends HeraldObjectAdapter { return $this->affectedRevision; } + private function loadCommitDiff() { + $drequest = DiffusionRequest::newFromDictionary( + array( + 'repository' => $this->repository, + 'commit' => $this->commit->getCommitIdentifier(), + )); + + $raw = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest) + ->setTimeout(60 * 60 * 15) + ->setLinesOfContext(0) + ->loadRawDiff(); + + $parser = new ArcanistDiffParser(); + $changes = $parser->parseDiff($raw); + + $diff = DifferentialDiff::newFromRawChanges($changes); + return $diff; + } + public function getHeraldField($field) { $data = $this->commitData; switch ($field) { @@ -117,30 +136,24 @@ final class HeraldCommitAdapter extends HeraldObjectAdapter { case HeraldFieldConfig::FIELD_REPOSITORY: return $this->repository->getPHID(); case HeraldFieldConfig::FIELD_DIFF_CONTENT: - // TODO! - return null; -/* try { - $diff = $this->loadDiff(); + $diff = $this->loadCommitDiff(); } catch (Exception $ex) { - // See rE280053 for an example. return array( - '<<< Failed to load diff, this usually means the change committed '. - 'a binary file as text. >>>', - ); + '<<< Failed to load diff, this may mean the change was '. + 'unimaginably enormous. >>>'); } $dict = array(); - $changes = $diff->getChangesets(); $lines = array(); + $changes = $diff->getChangesets(); foreach ($changes as $change) { $lines = array(); foreach ($change->getHunks() as $hunk) { $lines[] = $hunk->makeChanges(); } - $dict[$change->getTrueFilename()] = implode("\n", $lines); + $dict[$change->getFilename()] = implode("\n", $lines); } return $dict; -*/ case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE: $packages = $this->loadAffectedPackages(); return mpull($packages, 'getPHID');