Page MenuHomePhabricator

D14732.id35625.diff
No OneTemporary

D14732.id35625.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -692,6 +692,7 @@
'DiffusionRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionRawDiffQuery.php',
'DiffusionRawDiffQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionRawDiffQueryConduitAPIMethod.php',
'DiffusionReadmeView' => 'applications/diffusion/view/DiffusionReadmeView.php',
+ 'DiffusionRefDatasource' => 'applications/diffusion/typeahead/DiffusionRefDatasource.php',
'DiffusionRefNotFoundException' => 'applications/diffusion/exception/DiffusionRefNotFoundException.php',
'DiffusionRefTableController' => 'applications/diffusion/controller/DiffusionRefTableController.php',
'DiffusionRefsQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionRefsQueryConduitAPIMethod.php',
@@ -4566,6 +4567,7 @@
'DiffusionRawDiffQuery' => 'DiffusionQuery',
'DiffusionRawDiffQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
'DiffusionReadmeView' => 'DiffusionView',
+ 'DiffusionRefDatasource' => 'PhabricatorTypeaheadDatasource',
'DiffusionRefNotFoundException' => 'Exception',
'DiffusionRefTableController' => 'DiffusionController',
'DiffusionRefsQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
diff --git a/src/applications/diffusion/typeahead/DiffusionRefDatasource.php b/src/applications/diffusion/typeahead/DiffusionRefDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diffusion/typeahead/DiffusionRefDatasource.php
@@ -0,0 +1,50 @@
+<?php
+
+final class DiffusionRefDatasource
+ extends PhabricatorTypeaheadDatasource {
+
+ public function getBrowseTitle() {
+ return pht('Browse Branches');
+ }
+
+ public function getPlaceholderText() {
+ // TODO: This is really "branch, tag, bookmark or ref" but we are only
+ // using it to pick branches for now and sometimes the UI won't let you
+ // pick some of these types. See also "Browse Branches" above.
+ return pht('Type a branch name...');
+ }
+
+ public function getDatasourceApplicationClass() {
+ return 'PhabricatorDiffusionApplication';
+ }
+
+ public function loadResults() {
+ $viewer = $this->getViewer();
+ $raw_query = $this->getRawQuery();
+
+ $query = id(new PhabricatorRepositoryRefCursorQuery())
+ ->withDatasourceQuery($raw_query);
+
+ $types = $this->getParameter('refTypes');
+ if ($types) {
+ $query->withRefTypes($types);
+ }
+
+ $repository_phids = $this->getParameter('repositoryPHIDs');
+ if ($repository_phids) {
+ $query->withRepositoryPHIDs($repository_phids);
+ }
+
+ $refs = $this->executeQuery($query);
+
+ $results = array();
+ foreach ($refs as $ref) {
+ $results[] = id(new PhabricatorTypeaheadResult())
+ ->setName($ref->getRefName())
+ ->setPHID($ref->getPHID());
+ }
+
+ return $results;
+ }
+
+}
diff --git a/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php b/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
--- a/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
+++ b/src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
@@ -8,6 +8,7 @@
private $repositoryPHIDs;
private $refTypes;
private $refNames;
+ private $datasourceQuery;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -34,6 +35,11 @@
return $this;
}
+ public function withDatasourceQuery($query) {
+ $this->datasourceQuery = $query;
+ return $this;
+ }
+
public function newResultObject() {
return new PhabricatorRepositoryRefCursor();
}
@@ -108,6 +114,13 @@
$name_hashes);
}
+ if (strlen($this->datasourceQuery)) {
+ $where[] = qsprintf(
+ $conn,
+ 'refNameRaw LIKE %>',
+ $this->datasourceQuery);
+ }
+
return $where;
}

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 26, 6:51 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7632949
Default Alt Text
D14732.id35625.diff (3 KB)

Event Timeline