Path: blob/master/src/applications/differential/query/DifferentialRepositoryLookup.php
12256 views
<?php12/**3* Guess which tracked repository a diff comes from.4*/5final class DifferentialRepositoryLookup extends Phobject {67private $viewer;8private $diff;910public function setDiff(DifferentialDiff $diff) {11$this->diff = $diff;12return $this;13}1415public function setViewer(PhabricatorUser $viewer) {16$this->viewer = $viewer;17return $this;18}1920public function lookupRepository() {21$viewer = $this->viewer;22$diff = $this->diff;2324// Look for a repository UUID.25if ($diff->getRepositoryUUID()) {26$repositories = id(new PhabricatorRepositoryQuery())27->setViewer($viewer)28->withUUIDs(array($diff->getRepositoryUUID()))29->execute();30if ($repositories) {31return head($repositories);32}33}3435// Look for the base commit in Git and Mercurial.36$vcs = $diff->getSourceControlSystem();37$vcs_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;38$vcs_hg = PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL;39if ($vcs == $vcs_git || $vcs == $vcs_hg) {40$base = $diff->getSourceControlBaseRevision();41if ($base) {42$commits = id(new DiffusionCommitQuery())43->setViewer($viewer)44->withIdentifiers(array($base))45->execute();46$commits = mgroup($commits, 'getRepositoryID');47if (count($commits) == 1) {48$repository_id = key($commits);49$repositories = id(new PhabricatorRepositoryQuery())50->setViewer($viewer)51->withIDs(array($repository_id))52->execute();53if ($repositories) {54return head($repositories);55}56}57}58}5960// TODO: Compare SVN remote URIs? Compare Git/Hg remote URIs? Add61// an explicit option to `.arcconfig`?6263return null;64}6566}676869