Abstract raw diff rendering into DifferentialRawDiffRenderer
Test Plan: Enable inline patches: ``` bin/config set metamta.differential.patch-format 'unified' bin/config set metamta.differential.inline-patches 100000000 ``` Create a new diff and confirm it renders correctly via email. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Differential Revision: https://secure.phabricator.com/D7198
This commit is contained in:
@@ -391,6 +391,7 @@ phutil_register_library_map(array(
|
|||||||
'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php',
|
'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php',
|
||||||
'DifferentialPeopleMenuEventListener' => 'applications/differential/events/DifferentialPeopleMenuEventListener.php',
|
'DifferentialPeopleMenuEventListener' => 'applications/differential/events/DifferentialPeopleMenuEventListener.php',
|
||||||
'DifferentialPrimaryPaneView' => 'applications/differential/view/DifferentialPrimaryPaneView.php',
|
'DifferentialPrimaryPaneView' => 'applications/differential/view/DifferentialPrimaryPaneView.php',
|
||||||
|
'DifferentialRawDiffRenderer' => 'applications/differential/render/DifferentialRawDiffRenderer.php',
|
||||||
'DifferentialReleephRequestFieldSpecification' => 'applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php',
|
'DifferentialReleephRequestFieldSpecification' => 'applications/releeph/differential/DifferentialReleephRequestFieldSpecification.php',
|
||||||
'DifferentialRemarkupRule' => 'applications/differential/remarkup/DifferentialRemarkupRule.php',
|
'DifferentialRemarkupRule' => 'applications/differential/remarkup/DifferentialRemarkupRule.php',
|
||||||
'DifferentialReplyHandler' => 'applications/differential/mail/DifferentialReplyHandler.php',
|
'DifferentialReplyHandler' => 'applications/differential/mail/DifferentialReplyHandler.php',
|
||||||
|
|||||||
@@ -104,38 +104,16 @@ abstract class DifferentialReviewRequestMail extends DifferentialMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function buildPatch() {
|
private function buildPatch() {
|
||||||
$diff = new DifferentialDiff();
|
$renderer = new DifferentialRawDiffRenderer();
|
||||||
$diff->attachChangesets($this->getChangesets());
|
$renderer->setChangesets($this->getChangesets());
|
||||||
foreach ($diff->getChangesets() as $changeset) {
|
$renderer->setFormat(
|
||||||
$changeset->attachHunks(
|
PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'));
|
||||||
$changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$raw_changes = $diff->buildChangesList();
|
|
||||||
$changes = array();
|
|
||||||
foreach ($raw_changes as $changedict) {
|
|
||||||
$changes[] = ArcanistDiffChange::newFromDictionary($changedict);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: It would be nice to have a real viewer here eventually, but
|
// TODO: It would be nice to have a real viewer here eventually, but
|
||||||
// in the meantime anyone we're sending mail to can certainly see the
|
// in the meantime anyone we're sending mail to can certainly see the
|
||||||
// patch.
|
// patch.
|
||||||
$loader = id(new PhabricatorFileBundleLoader())
|
$renderer->setViewer(PhabricatorUser::getOmnipotentUser());
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser());
|
return $renderer->buildPatch();
|
||||||
|
|
||||||
$bundle = ArcanistBundle::newFromChanges($changes);
|
|
||||||
$bundle->setLoadFileDataCallback(array($loader, 'loadFileData'));
|
|
||||||
|
|
||||||
$format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format');
|
|
||||||
switch ($format) {
|
|
||||||
case 'git':
|
|
||||||
return $bundle->toGitPatch();
|
|
||||||
break;
|
|
||||||
case 'unified':
|
|
||||||
default:
|
|
||||||
return $bundle->toUnifiedDiff();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMailTags() {
|
protected function getMailTags() {
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
final class DifferentialRawDiffRenderer {
|
||||||
|
|
||||||
|
private $changesets;
|
||||||
|
private $format = 'unified';
|
||||||
|
private $viewer;
|
||||||
|
|
||||||
|
public function setFormat($format) {
|
||||||
|
$this->format = $format;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormat() {
|
||||||
|
return $this->format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setChangesets(array $changesets) {
|
||||||
|
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||||
|
|
||||||
|
$this->changesets = $changesets;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChangesets() {
|
||||||
|
return $this->changesets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setViewer(PhabricatorUser $viewer) {
|
||||||
|
$this->viewer = $viewer;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getViewer() {
|
||||||
|
return $this->viewer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildPatch() {
|
||||||
|
$diff = new DifferentialDiff();
|
||||||
|
$diff->attachChangesets($this->getChangesets());
|
||||||
|
foreach ($diff->getChangesets() as $changeset) {
|
||||||
|
$changeset->attachHunks(
|
||||||
|
$changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$raw_changes = $diff->buildChangesList();
|
||||||
|
$changes = array();
|
||||||
|
foreach ($raw_changes as $changedict) {
|
||||||
|
$changes[] = ArcanistDiffChange::newFromDictionary($changedict);
|
||||||
|
}
|
||||||
|
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$loader = id(new PhabricatorFileBundleLoader())
|
||||||
|
->setViewer($viewer);
|
||||||
|
|
||||||
|
$bundle = ArcanistBundle::newFromChanges($changes);
|
||||||
|
$bundle->setLoadFileDataCallback(array($loader, 'loadFileData'));
|
||||||
|
|
||||||
|
$format = $this->getFormat();
|
||||||
|
switch ($format) {
|
||||||
|
case 'git':
|
||||||
|
return $bundle->toGitPatch();
|
||||||
|
break;
|
||||||
|
case 'unified':
|
||||||
|
default:
|
||||||
|
return $bundle->toUnifiedDiff();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user