mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 17:52:43 +01:00
021223907d
Summary: Ref T7604. Remove arcanist projects from differential. Depends on D12687 and D12893. Test Plan: Submitted a diff. Patched the diff with `arc patch`. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7604 Differential Revision: https://secure.phabricator.com/D12894
67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?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 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;
|
|
}
|
|
|
|
}
|