Changeset View
Changeset View
Standalone View
Standalone View
src/repository/marker/ArcanistRepositoryMarkerQuery.php
| <?php | <?php | ||||
| abstract class ArcanistRepositoryMarkerQuery | abstract class ArcanistRepositoryMarkerQuery | ||||
| extends ArcanistRepositoryQuery { | extends ArcanistRepositoryQuery { | ||||
| private $isActive; | private $isActive; | ||||
| private $markerTypes; | private $markerTypes; | ||||
| private $names; | private $names; | ||||
| private $commitHashes; | private $commitHashes; | ||||
| private $ancestorCommitHashes; | private $ancestorCommitHashes; | ||||
| private $remotes; | |||||
| final public function withMarkerTypes(array $types) { | final public function withMarkerTypes(array $types) { | ||||
| $this->markerTypes = array_fuse($types); | $this->markerTypes = array_fuse($types); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function withNames(array $names) { | final public function withNames(array $names) { | ||||
| $this->names = array_fuse($names); | $this->names = array_fuse($names); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function withRemotes(array $remotes) { | |||||
| assert_instances_of($remotes, 'ArcanistRemoteRef'); | |||||
| $this->remotes = $remotes; | |||||
| return $this; | |||||
| } | |||||
| final public function withIsActive($active) { | final public function withIsActive($active) { | ||||
| $this->isActive = $active; | $this->isActive = $active; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function execute() { | final public function execute() { | ||||
| $markers = $this->newRefMarkers(); | $remotes = $this->remotes; | ||||
| if ($remotes !== null) { | |||||
| $marker_lists = array(); | |||||
| foreach ($remotes as $remote) { | |||||
| $marker_list = $this->newRemoteRefMarkers($remote); | |||||
| foreach ($marker_list as $marker) { | |||||
| $marker->attachRemoteRef($remote); | |||||
| } | |||||
| $marker_lists[] = $marker_list; | |||||
| } | |||||
| $markers = array_mergev($marker_lists); | |||||
| } else { | |||||
| $markers = $this->newLocalRefMarkers(); | |||||
| foreach ($markers as $marker) { | |||||
| $marker->attachRemoteRef(null); | |||||
| } | |||||
| } | |||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| foreach ($markers as $marker) { | foreach ($markers as $marker) { | ||||
| $state_ref = id(new ArcanistWorkingCopyStateRef()) | $state_ref = id(new ArcanistWorkingCopyStateRef()) | ||||
| ->setCommitRef($marker->getCommitRef()); | ->setCommitRef($marker->getCommitRef()); | ||||
| $marker->attachWorkingCopyStateRef($state_ref); | $marker->attachWorkingCopyStateRef($state_ref); | ||||
| Show All 23 Lines | final public function execute() { | ||||
| if ($this->isActive !== null) { | if ($this->isActive !== null) { | ||||
| foreach ($markers as $key => $marker) { | foreach ($markers as $key => $marker) { | ||||
| if ($marker->getIsActive() !== $this->isActive) { | if ($marker->getIsActive() !== $this->isActive) { | ||||
| unset($markers[$key]); | 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. | ||||
| Show All 10 Lines | abstract class ArcanistRepositoryMarkerQuery | ||||
| final protected function shouldQueryMarkerType($marker_type) { | final protected function shouldQueryMarkerType($marker_type) { | ||||
| if ($this->markerTypes === null) { | if ($this->markerTypes === null) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| return isset($this->markerTypes[$marker_type]); | return isset($this->markerTypes[$marker_type]); | ||||
| } | } | ||||
| abstract protected function newLocalRefMarkers(); | |||||
| abstract protected function newRemoteRefMarkers(ArcanistRemoteRef $remote); | |||||
| } | } | ||||