Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/render/DifferentialRawDiffRenderer.php
12256 views
1
<?php
2
3
final class DifferentialRawDiffRenderer extends Phobject {
4
5
private $changesets;
6
private $format = 'unified';
7
private $viewer;
8
private $byteLimit;
9
10
public function setFormat($format) {
11
$this->format = $format;
12
return $this;
13
}
14
15
public function getFormat() {
16
return $this->format;
17
}
18
19
public function setChangesets(array $changesets) {
20
assert_instances_of($changesets, 'DifferentialChangeset');
21
22
$this->changesets = $changesets;
23
return $this;
24
}
25
26
public function getChangesets() {
27
return $this->changesets;
28
}
29
30
public function setViewer(PhabricatorUser $viewer) {
31
$this->viewer = $viewer;
32
return $this;
33
}
34
35
public function getViewer() {
36
return $this->viewer;
37
}
38
39
public function setByteLimit($byte_limit) {
40
$this->byteLimit = $byte_limit;
41
return $this;
42
}
43
44
public function getByteLimit() {
45
return $this->byteLimit;
46
}
47
48
public function buildPatch() {
49
$diff = new DifferentialDiff();
50
$diff->attachChangesets($this->getChangesets());
51
52
$raw_changes = $diff->buildChangesList();
53
$changes = array();
54
foreach ($raw_changes as $changedict) {
55
$changes[] = ArcanistDiffChange::newFromDictionary($changedict);
56
}
57
58
$viewer = $this->getViewer();
59
$loader = id(new PhabricatorFileBundleLoader())
60
->setViewer($viewer);
61
62
$bundle = ArcanistBundle::newFromChanges($changes);
63
$bundle->setLoadFileDataCallback(array($loader, 'loadFileData'));
64
65
$byte_limit = $this->getByteLimit();
66
if ($byte_limit) {
67
$bundle->setByteLimit($byte_limit);
68
}
69
70
$format = $this->getFormat();
71
switch ($format) {
72
case 'git':
73
return $bundle->toGitPatch();
74
case 'unified':
75
default:
76
return $bundle->toUnifiedDiff();
77
}
78
}
79
}
80
81