[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/query/ -> DifferentialRepositoryLookup.php (source)

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


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1