mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
71e9fb96b5
Summary: Ref T5179. Ref T4045. I want to move all hunk loads into DifferentialHunkQuery so I can make it do magical things where hunks come from multiple places, handle non-utf8 encodings properly, handle compression, archive into Files, and so on. Test Plan: Viewed some revisions. Called `differential.getrawdiff`. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4045, T5179 Differential Revision: https://secure.phabricator.com/D9287
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?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());
|
|
|
|
$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;
|
|
}
|
|
}
|
|
}
|