Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / differential / query / DifferentialRepositoryLookup.php
blob4a498edb55d4ca7062d7fe8ea9a7e19d1727d0fc
1 <?php
3 /**
4 * Guess which tracked repository a diff comes from.
5 */
6 final class DifferentialRepositoryLookup extends Phobject {
8 private $viewer;
9 private $diff;
11 public function setDiff(DifferentialDiff $diff) {
12 $this->diff = $diff;
13 return $this;
16 public function setViewer(PhabricatorUser $viewer) {
17 $this->viewer = $viewer;
18 return $this;
21 public function lookupRepository() {
22 $viewer = $this->viewer;
23 $diff = $this->diff;
25 // Look for a repository UUID.
26 if ($diff->getRepositoryUUID()) {
27 $repositories = id(new PhabricatorRepositoryQuery())
28 ->setViewer($viewer)
29 ->withUUIDs(array($diff->getRepositoryUUID()))
30 ->execute();
31 if ($repositories) {
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();
42 if ($base) {
43 $commits = id(new DiffusionCommitQuery())
44 ->setViewer($viewer)
45 ->withIdentifiers(array($base))
46 ->execute();
47 $commits = mgroup($commits, 'getRepositoryID');
48 if (count($commits) == 1) {
49 $repository_id = key($commits);
50 $repositories = id(new PhabricatorRepositoryQuery())
51 ->setViewer($viewer)
52 ->withIDs(array($repository_id))
53 ->execute();
54 if ($repositories) {
55 return head($repositories);
61 // TODO: Compare SVN remote URIs? Compare Git/Hg remote URIs? Add
62 // an explicit option to `.arcconfig`?
64 return null;