Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F75374
D7384.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D7384.diff
View Options
diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php
--- a/src/applications/herald/adapter/HeraldCommitAdapter.php
+++ b/src/applications/herald/adapter/HeraldCommitAdapter.php
@@ -17,6 +17,7 @@
protected $repository;
protected $commit;
protected $commitData;
+ private $commitDiff;
protected $emailPHIDs = array();
protected $addCCPHIDs = array();
@@ -272,15 +273,50 @@
return $diff;
}
- private function loadChangesets() {
- try {
- $diff = $this->loadCommitDiff();
- } catch (Exception $ex) {
+ private function getDiffContent($type) {
+ if ($this->commitDiff === null) {
+ try {
+ $this->commitDiff = $this->loadCommitDiff();
+ } catch (Exception $ex) {
+ $this->commitDiff = $ex;
+ phlog($ex);
+ }
+ }
+
+ if ($this->commitDiff instanceof Exception) {
+ $ex = $this->commitDiff;
+ $ex_class = get_class($ex);
+ $ex_message = pht('Failed to load changes: %s', $ex->getMessage());
+
return array(
- '<<< Failed to load diff, this may mean the change was '.
- 'unimaginably enormous. >>>');
+ '<'.$ex_class.'>' => $ex_message,
+ );
}
- return $diff->getChangesets();
+
+ $changes = $this->commitDiff->getChangesets();
+
+ $result = array();
+ foreach ($changes as $change) {
+ $lines = array();
+ foreach ($change->getHunks() as $hunk) {
+ switch ($type) {
+ case '-':
+ $lines[] = $hunk->makeOldFile();
+ break;
+ case '+':
+ $lines[] = $hunk->makeNewFile();
+ break;
+ case '*':
+ $lines[] = $hunk->makeChanges();
+ break;
+ default:
+ throw new Exception("Unknown content selection '{$type}'!");
+ }
+ }
+ $result[$change->getFilename()] = implode("\n", $lines);
+ }
+
+ return $result;
}
public function getHeraldField($field) {
@@ -299,41 +335,11 @@
case self::FIELD_REPOSITORY:
return $this->repository->getPHID();
case self::FIELD_DIFF_CONTENT:
- $dict = array();
- $lines = array();
- $changes = $this->loadChangesets();
- foreach ($changes as $change) {
- $lines = array();
- foreach ($change->getHunks() as $hunk) {
- $lines[] = $hunk->makeChanges();
- }
- $dict[$change->getFilename()] = implode("\n", $lines);
- }
- return $dict;
+ return $this->getDiffContent('*');
case self::FIELD_DIFF_ADDED_CONTENT:
- $dict = array();
- $lines = array();
- $changes = $this->loadChangesets();
- foreach ($changes as $change) {
- $lines = array();
- foreach ($change->getHunks() as $hunk) {
- $lines[] = implode('', $hunk->getAddedLines());
- }
- $dict[$change->getFilename()] = implode("\n", $lines);
- }
- return $dict;
+ return $this->getDiffContent('+');
case self::FIELD_DIFF_REMOVED_CONTENT:
- $dict = array();
- $lines = array();
- $changes = $this->loadChangesets();
- foreach ($changes as $change) {
- $lines = array();
- foreach ($change->getHunks() as $hunk) {
- $lines[] = implode('', $hunk->getRemovedLines());
- }
- $dict[$change->getFilename()] = implode("\n", $lines);
- }
- return $dict;
+ return $this->getDiffContent('-');
case self::FIELD_AFFECTED_PACKAGE:
$packages = $this->loadAffectedPackages();
return mpull($packages, 'getPHID');
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/pk/22/pg2a4n4pig5j3gg3
Default Alt Text
D7384.diff (3 KB)
Attached To
Mode
D7384: Improve exception behavior for Herald commit rules which fail to load diff context
Attached
Detach File
Event Timeline
Log In to Comment