forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDifferentialRepositoryLookup.php
83 lines (72 loc) · 2.31 KB
/
DifferentialRepositoryLookup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Guess which tracked repository a diff comes from.
*/
final class DifferentialRepositoryLookup extends Phobject {
private $viewer;
private $diff;
public function setDiff(DifferentialDiff $diff) {
$this->diff = $diff;
return $this;
}
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function lookupRepository() {
$viewer = $this->viewer;
$diff = $this->diff;
// Look for an explicit Arcanist project.
if ($diff->getArcanistProjectPHID()) {
$project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
'phid = %s',
$diff->getArcanistProjectPHID());
if ($project && $project->getRepositoryID()) {
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withIDs(array($project->getRepositoryID()))
->execute();
if ($repositories) {
return head($repositories);
}
}
}
// Look for a repository UUID.
if ($diff->getRepositoryUUID()) {
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withUUIDs(array($diff->getRepositoryUUID()))
->execute();
if ($repositories) {
return head($repositories);
}
}
// Look for the base commit in Git and Mercurial.
$vcs = $diff->getSourceControlSystem();
$vcs_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
$vcs_hg = PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL;
if ($vcs == $vcs_git || $vcs == $vcs_hg) {
$base = $diff->getSourceControlBaseRevision();
if ($base) {
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIdentifiers(array($base))
->execute();
$commits = mgroup($commits, 'getRepositoryID');
if (count($commits) == 1) {
$repository_id = key($commits);
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withIDs(array($repository_id))
->execute();
if ($repositories) {
return head($repositories);
}
}
}
}
// TODO: Compare SVN remote URIs? Compare Git/Hg remote URIs? Add
// an explicit option to `.arcconfig`?
return null;
}
}