mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-23 21:18:19 +01:00
26d0862f4f
Summary: Ref T13137. See PHI592. Depends on D19444. Apply a limit up front to stop patches which are way too big (e.g., 600MB of videos) from generating in the first place. Test Plan: - Configured inline patches in git format. - Created a normal revision, got an inline git patch. - Created a revision with a 10MB video file, got no inline patch. - (Added a bunch of debugging stuff to make sure the internal pathway was working.) Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13137 Differential Revision: https://secure.phabricator.com/D19445
79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
final class DifferentialRawDiffRenderer extends Phobject {
|
|
|
|
private $changesets;
|
|
private $format = 'unified';
|
|
private $viewer;
|
|
private $byteLimit;
|
|
|
|
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 setByteLimit($byte_limit) {
|
|
$this->byteLimit = $byte_limit;
|
|
return $this;
|
|
}
|
|
|
|
public function getByteLimit() {
|
|
return $this->byteLimit;
|
|
}
|
|
|
|
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'));
|
|
|
|
$byte_limit = $this->getByteLimit();
|
|
if ($byte_limit) {
|
|
$bundle->setByteLimit($byte_limit);
|
|
}
|
|
|
|
$format = $this->getFormat();
|
|
switch ($format) {
|
|
case 'git':
|
|
return $bundle->toGitPatch();
|
|
case 'unified':
|
|
default:
|
|
return $bundle->toUnifiedDiff();
|
|
}
|
|
}
|
|
}
|