Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/data/DiffusionPathChange.php
12241 views
1
<?php
2
3
final class DiffusionPathChange extends Phobject {
4
5
private $path;
6
private $commitIdentifier;
7
private $commit;
8
private $commitData;
9
10
private $changeType;
11
private $fileType;
12
private $targetPath;
13
private $targetCommitIdentifier;
14
private $awayPaths = array();
15
16
public function setPath($path) {
17
$this->path = $path;
18
return $this;
19
}
20
21
public function getPath() {
22
return $this->path;
23
}
24
25
public function setChangeType($change_type) {
26
$this->changeType = $change_type;
27
return $this;
28
}
29
30
public function getChangeType() {
31
return $this->changeType;
32
}
33
34
public function setFileType($file_type) {
35
$this->fileType = $file_type;
36
return $this;
37
}
38
39
public function getFileType() {
40
return $this->fileType;
41
}
42
43
public function setTargetPath($target_path) {
44
$this->targetPath = $target_path;
45
return $this;
46
}
47
48
public function getTargetPath() {
49
return $this->targetPath;
50
}
51
52
public function setAwayPaths(array $away_paths) {
53
$this->awayPaths = $away_paths;
54
return $this;
55
}
56
57
public function getAwayPaths() {
58
return $this->awayPaths;
59
}
60
61
public function setCommitIdentifier($commit) {
62
$this->commitIdentifier = $commit;
63
return $this;
64
}
65
66
public function getCommitIdentifier() {
67
return $this->commitIdentifier;
68
}
69
70
public function setTargetCommitIdentifier($target_commit_identifier) {
71
$this->targetCommitIdentifier = $target_commit_identifier;
72
return $this;
73
}
74
75
public function getTargetCommitIdentifier() {
76
return $this->targetCommitIdentifier;
77
}
78
79
public function setCommit($commit) {
80
$this->commit = $commit;
81
return $this;
82
}
83
84
public function getCommit() {
85
return $this->commit;
86
}
87
88
public function setCommitData($commit_data) {
89
$this->commitData = $commit_data;
90
return $this;
91
}
92
93
public function getCommitData() {
94
return $this->commitData;
95
}
96
97
98
public function getEpoch() {
99
if ($this->getCommit()) {
100
return $this->getCommit()->getEpoch();
101
}
102
return null;
103
}
104
105
public function getAuthorName() {
106
if ($this->getCommitData()) {
107
return $this->getCommitData()->getAuthorString();
108
}
109
return null;
110
}
111
112
public function getSummary() {
113
if (!$this->getCommitData()) {
114
return null;
115
}
116
return $this->getCommitData()->getSummary();
117
}
118
119
public static function convertToArcanistChanges(array $changes) {
120
assert_instances_of($changes, __CLASS__);
121
$direct = array();
122
$result = array();
123
foreach ($changes as $path) {
124
$change = new ArcanistDiffChange();
125
$change->setCurrentPath($path->getPath());
126
$direct[] = $path->getPath();
127
$change->setType($path->getChangeType());
128
$file_type = $path->getFileType();
129
if ($file_type == DifferentialChangeType::FILE_NORMAL) {
130
$file_type = DifferentialChangeType::FILE_TEXT;
131
}
132
$change->setFileType($file_type);
133
$change->setOldPath($path->getTargetPath());
134
foreach ($path->getAwayPaths() as $away_path) {
135
$change->addAwayPath($away_path);
136
}
137
$result[$path->getPath()] = $change;
138
}
139
140
return array_select_keys($result, $direct);
141
}
142
143
public static function convertToDifferentialChangesets(
144
PhabricatorUser $user,
145
array $changes) {
146
assert_instances_of($changes, __CLASS__);
147
$arcanist_changes = self::convertToArcanistChanges($changes);
148
$diff = DifferentialDiff::newEphemeralFromRawChanges(
149
$arcanist_changes);
150
return $diff->getChangesets();
151
}
152
153
public function toDictionary() {
154
$commit = $this->getCommit();
155
if ($commit) {
156
$commit_dict = $commit->toDictionary();
157
} else {
158
$commit_dict = array();
159
}
160
$commit_data = $this->getCommitData();
161
if ($commit_data) {
162
$commit_data_dict = $commit_data->toDictionary();
163
} else {
164
$commit_data_dict = array();
165
}
166
return array(
167
'path' => $this->getPath(),
168
'commitIdentifier' => $this->getCommitIdentifier(),
169
'commit' => $commit_dict,
170
'commitData' => $commit_data_dict,
171
'fileType' => $this->getFileType(),
172
'changeType' => $this->getChangeType(),
173
'targetPath' => $this->getTargetPath(),
174
'targetCommitIdentifier' => $this->getTargetCommitIdentifier(),
175
'awayPaths' => $this->getAwayPaths(),
176
);
177
}
178
179
public static function newFromConduit(array $dicts) {
180
$results = array();
181
foreach ($dicts as $dict) {
182
$commit = PhabricatorRepositoryCommit::newFromDictionary($dict['commit']);
183
$commit_data =
184
PhabricatorRepositoryCommitData::newFromDictionary(
185
$dict['commitData']);
186
$results[] = id(new DiffusionPathChange())
187
->setPath($dict['path'])
188
->setCommitIdentifier($dict['commitIdentifier'])
189
->setCommit($commit)
190
->setCommitData($commit_data)
191
->setFileType($dict['fileType'])
192
->setChangeType($dict['changeType'])
193
->setTargetPath($dict['targetPath'])
194
->setTargetCommitIdentifier($dict['targetCommitIdentifier'])
195
->setAwayPaths($dict['awayPaths']);
196
}
197
return $results;
198
}
199
200
}
201
202