4 * Guess which tracked repository a diff comes from.
6 final class DifferentialRepositoryLookup
extends Phobject
{
11 public function setDiff(DifferentialDiff
$diff) {
16 public function setViewer(PhabricatorUser
$viewer) {
17 $this->viewer
= $viewer;
21 public function lookupRepository() {
22 $viewer = $this->viewer
;
25 // Look for a repository UUID.
26 if ($diff->getRepositoryUUID()) {
27 $repositories = id(new PhabricatorRepositoryQuery())
29 ->withUUIDs(array($diff->getRepositoryUUID()))
32 return head($repositories);
36 // Look for the base commit in Git and Mercurial.
37 $vcs = $diff->getSourceControlSystem();
38 $vcs_git = PhabricatorRepositoryType
::REPOSITORY_TYPE_GIT
;
39 $vcs_hg = PhabricatorRepositoryType
::REPOSITORY_TYPE_MERCURIAL
;
40 if ($vcs == $vcs_git ||
$vcs == $vcs_hg) {
41 $base = $diff->getSourceControlBaseRevision();
43 $commits = id(new DiffusionCommitQuery())
45 ->withIdentifiers(array($base))
47 $commits = mgroup($commits, 'getRepositoryID');
48 if (count($commits) == 1) {
49 $repository_id = key($commits);
50 $repositories = id(new PhabricatorRepositoryQuery())
52 ->withIDs(array($repository_id))
55 return head($repositories);
61 // TODO: Compare SVN remote URIs? Compare Git/Hg remote URIs? Add
62 // an explicit option to `.arcconfig`?