Changeset View
Changeset View
Standalone View
Standalone View
src/repository/marker/ArcanistRepositoryMarkerQuery.php
<?php | <?php | ||||
abstract class ArcanistRepositoryMarkerQuery | abstract class ArcanistRepositoryMarkerQuery | ||||
extends Phobject { | extends Phobject { | ||||
private $repositoryAPI; | private $repositoryAPI; | ||||
private $types; | private $isActive; | ||||
private $markerTypes; | |||||
private $commitHashes; | private $commitHashes; | ||||
private $ancestorCommitHashes; | private $ancestorCommitHashes; | ||||
final public function setRepositoryAPI(ArcanistRepositoryAPI $api) { | final public function setRepositoryAPI(ArcanistRepositoryAPI $api) { | ||||
$this->repositoryAPI = $api; | $this->repositoryAPI = $api; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function getRepositoryAPI() { | final public function getRepositoryAPI() { | ||||
return $this->repositoryAPI; | return $this->repositoryAPI; | ||||
} | } | ||||
final public function withTypes(array $types) { | final public function withMarkerTypes(array $types) { | ||||
$this->types = array_fuse($types); | $this->markerTypes = array_fuse($types); | ||||
return $this; | |||||
} | |||||
final public function withIsActive($active) { | |||||
$this->isActive = $active; | |||||
return $this; | return $this; | ||||
} | } | ||||
final public function execute() { | final public function execute() { | ||||
$markers = $this->newRefMarkers(); | $markers = $this->newRefMarkers(); | ||||
$types = $this->types; | $types = $this->markerTypes; | ||||
if ($types !== null) { | if ($types !== null) { | ||||
foreach ($markers as $key => $marker) { | foreach ($markers as $key => $marker) { | ||||
if (!isset($types[$marker->getMarkerType()])) { | if (!isset($types[$marker->getMarkerType()])) { | ||||
unset($markers[$key]); | unset($markers[$key]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($this->isActive !== null) { | |||||
foreach ($markers as $key => $marker) { | |||||
if ($marker->getIsActive() !== $this->isActive) { | |||||
unset($markers[$key]); | |||||
} | |||||
} | |||||
} | |||||
return $this->sortMarkers($markers); | return $this->sortMarkers($markers); | ||||
} | } | ||||
private function sortMarkers(array $markers) { | private function sortMarkers(array $markers) { | ||||
// Sort the list in natural order. If we apply a stable sort later, | // Sort the list in natural order. If we apply a stable sort later, | ||||
// markers will sort in "feature1", "feature2", etc., order if they | // markers will sort in "feature1", "feature2", etc., order if they | ||||
// don't otherwise have a unique position. | // don't otherwise have a unique position. | ||||
// This can improve behavior if two branches were updated at the same | // This can improve behavior if two branches were updated at the same | ||||
// time, as is common when cascading rebases after changes land. | // time, as is common when cascading rebases after changes land. | ||||
$map = mpull($markers, 'getName'); | $map = mpull($markers, 'getName'); | ||||
natcasesort($map); | natcasesort($map); | ||||
$markers = array_select_keys($markers, array_keys($map)); | $markers = array_select_keys($markers, array_keys($map)); | ||||
return $markers; | return $markers; | ||||
} | } | ||||
final protected function shouldQueryMarkerType($marker_type) { | final protected function shouldQueryMarkerType($marker_type) { | ||||
if ($this->types === null) { | if ($this->markerTypes === null) { | ||||
return true; | return true; | ||||
} | } | ||||
return isset($this->types[$marker_type]); | return isset($this->markerTypes[$marker_type]); | ||||
} | } | ||||
} | } |