Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/herald/HeraldDifferentialAdapter.php
12256 views
1
<?php
2
3
abstract class HeraldDifferentialAdapter extends HeraldAdapter {
4
5
private $repository = false;
6
private $diff;
7
8
abstract protected function loadChangesets();
9
abstract protected function loadChangesetsWithHunks();
10
11
public function getDiff() {
12
return $this->diff;
13
}
14
15
public function setDiff(DifferentialDiff $diff) {
16
$this->diff = $diff;
17
return $this;
18
}
19
20
public function loadRepository() {
21
if ($this->repository === false) {
22
$repository_phid = $this->getObject()->getRepositoryPHID();
23
24
if ($repository_phid) {
25
$repository = id(new PhabricatorRepositoryQuery())
26
->setViewer(PhabricatorUser::getOmnipotentUser())
27
->withPHIDs(array($repository_phid))
28
->executeOne();
29
} else {
30
$repository = null;
31
}
32
33
$this->repository = $repository;
34
}
35
36
return $this->repository;
37
}
38
39
40
public function loadAffectedPaths() {
41
$changesets = $this->loadChangesets();
42
43
$paths = array();
44
foreach ($changesets as $changeset) {
45
$paths[] = $this->getAbsoluteRepositoryPathForChangeset($changeset);
46
}
47
48
return $paths;
49
}
50
51
protected function getAbsoluteRepositoryPathForChangeset(
52
DifferentialChangeset $changeset) {
53
54
$repository = $this->loadRepository();
55
if (!$repository) {
56
return '/'.ltrim($changeset->getFilename(), '/');
57
}
58
59
$diff = $this->getDiff();
60
61
return $changeset->getAbsoluteRepositoryPath($repository, $diff);
62
}
63
64
public function loadContentDictionary() {
65
$add_lines = DifferentialHunk::FLAG_LINES_ADDED;
66
$rem_lines = DifferentialHunk::FLAG_LINES_REMOVED;
67
$mask = ($add_lines | $rem_lines);
68
return $this->loadContentWithMask($mask);
69
}
70
71
public function loadAddedContentDictionary() {
72
return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_ADDED);
73
}
74
75
public function loadRemovedContentDictionary() {
76
return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_REMOVED);
77
}
78
79
protected function loadContentWithMask($mask) {
80
$changesets = $this->loadChangesetsWithHunks();
81
82
$dict = array();
83
foreach ($changesets as $changeset) {
84
$content = array();
85
foreach ($changeset->getHunks() as $hunk) {
86
$content[] = $hunk->getContentWithMask($mask);
87
}
88
89
$path = $this->getAbsoluteRepositoryPathForChangeset($changeset);
90
$dict[$path] = implode("\n", $content);
91
}
92
93
return $dict;
94
}
95
96
}
97
98