Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/query/DiffusionRenameHistoryQuery.php
12242 views
1
<?php
2
3
final class DiffusionRenameHistoryQuery extends Phobject {
4
5
private $oldCommit;
6
private $wasCreated;
7
private $request;
8
private $viewer;
9
10
public function setViewer(PhabricatorUser $viewer) {
11
$this->viewer = $viewer;
12
return $this;
13
}
14
15
public function getWasCreated() {
16
return $this->wasCreated;
17
}
18
19
public function setRequest(DiffusionRequest $request) {
20
$this->request = $request;
21
return $this;
22
}
23
24
public function setOldCommit($old_commit) {
25
$this->oldCommit = $old_commit;
26
return $this;
27
}
28
29
public function getOldCommit() {
30
return $this->oldCommit;
31
}
32
33
public function loadOldFilename() {
34
$drequest = $this->request;
35
$repository_id = $drequest->getRepository()->getID();
36
$conn_r = id(new PhabricatorRepository())->establishConnection('r');
37
38
$commit_id = $this->loadCommitId($this->oldCommit);
39
$old_commit_sequence = $this->loadCommitSequence($commit_id);
40
41
$path = '/'.$drequest->getPath();
42
$commit_id = $this->loadCommitId($drequest->getCommit());
43
44
do {
45
$commit_sequence = $this->loadCommitSequence($commit_id);
46
$change = queryfx_one(
47
$conn_r,
48
'SELECT pc.changeType, pc.targetCommitID, tp.path
49
FROM %T p
50
JOIN %T pc ON p.id = pc.pathID
51
LEFT JOIN %T tp ON pc.targetPathID = tp.id
52
WHERE p.pathHash = %s
53
AND pc.repositoryID = %d
54
AND pc.changeType IN (%d, %d)
55
AND pc.commitSequence BETWEEN %d AND %d
56
ORDER BY pc.commitSequence DESC
57
LIMIT 1',
58
PhabricatorRepository::TABLE_PATH,
59
PhabricatorRepository::TABLE_PATHCHANGE,
60
PhabricatorRepository::TABLE_PATH,
61
md5($path),
62
$repository_id,
63
ArcanistDiffChangeType::TYPE_MOVE_HERE,
64
ArcanistDiffChangeType::TYPE_ADD,
65
$old_commit_sequence,
66
$commit_sequence);
67
if ($change) {
68
if ($change['changeType'] == ArcanistDiffChangeType::TYPE_ADD) {
69
$this->wasCreated = true;
70
return $path;
71
}
72
$commit_id = $change['targetCommitID'];
73
$path = $change['path'];
74
}
75
} while ($change && $path);
76
77
return $path;
78
}
79
80
private function loadCommitId($commit_identifier) {
81
$commit = id(new DiffusionCommitQuery())
82
->setViewer($this->viewer)
83
->withIdentifiers(array($commit_identifier))
84
->withRepository($this->request->getRepository())
85
->executeOne();
86
return $commit->getID();
87
}
88
89
private function loadCommitSequence($commit_id) {
90
$conn_r = id(new PhabricatorRepository())->establishConnection('r');
91
$path_change = queryfx_one(
92
$conn_r,
93
'SELECT commitSequence
94
FROM %T
95
WHERE repositoryID = %d AND commitID = %d
96
LIMIT 1',
97
PhabricatorRepository::TABLE_PATHCHANGE,
98
$this->request->getRepository()->getID(),
99
$commit_id);
100
return reset($path_change);
101
}
102
103
}
104
105