mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 04:42:40 +01:00
Add proper PHIDs to RefCursors
Summary: Ref T9952. See discussion there. This change is primarily aimed at letting me build a typeahead of branches in a repository so that we can land to arbitrary branches a few diffs from now. Test Plan: - Ran migrations. - Verified database populated properly with PHIDs (`SELECT * FROM repository_refcursor;`). - Ran `bin/repository update`. - Viewed a Git repository in Diffusion. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9952 Differential Revision: https://secure.phabricator.com/D14731
This commit is contained in:
parent
6985643f58
commit
2a203fbab1
6 changed files with 109 additions and 24 deletions
2
resources/sql/autopatches/20151210.land.1.refphid.sql
Normal file
2
resources/sql/autopatches/20151210.land.1.refphid.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_repository.repository_refcursor
|
||||||
|
ADD phid VARBINARY(64) NOT NULL AFTER id;
|
17
resources/sql/autopatches/20151210.land.2.refphid.php
Normal file
17
resources/sql/autopatches/20151210.land.2.refphid.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$table = new PhabricatorRepositoryRefCursor();
|
||||||
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $cursor) {
|
||||||
|
if (strlen($cursor->getPHID())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'UPDATE %T SET phid = %s WHERE id = %d',
|
||||||
|
$table->getTableName(),
|
||||||
|
$table->generatePHID(),
|
||||||
|
$cursor->getID());
|
||||||
|
}
|
|
@ -2907,6 +2907,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRepositoryPushReplyHandler' => 'applications/repository/mail/PhabricatorRepositoryPushReplyHandler.php',
|
'PhabricatorRepositoryPushReplyHandler' => 'applications/repository/mail/PhabricatorRepositoryPushReplyHandler.php',
|
||||||
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
|
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
|
||||||
'PhabricatorRepositoryRefCursor' => 'applications/repository/storage/PhabricatorRepositoryRefCursor.php',
|
'PhabricatorRepositoryRefCursor' => 'applications/repository/storage/PhabricatorRepositoryRefCursor.php',
|
||||||
|
'PhabricatorRepositoryRefCursorPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRefCursorPHIDType.php',
|
||||||
'PhabricatorRepositoryRefCursorQuery' => 'applications/repository/query/PhabricatorRepositoryRefCursorQuery.php',
|
'PhabricatorRepositoryRefCursorQuery' => 'applications/repository/query/PhabricatorRepositoryRefCursorQuery.php',
|
||||||
'PhabricatorRepositoryRefEngine' => 'applications/repository/engine/PhabricatorRepositoryRefEngine.php',
|
'PhabricatorRepositoryRefEngine' => 'applications/repository/engine/PhabricatorRepositoryRefEngine.php',
|
||||||
'PhabricatorRepositoryRepositoryPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php',
|
'PhabricatorRepositoryRepositoryPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php',
|
||||||
|
@ -7199,6 +7200,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRepositoryDAO',
|
'PhabricatorRepositoryDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
|
'PhabricatorRepositoryRefCursorPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorRepositoryRefCursorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorRepositoryRefCursorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorRepositoryRefEngine' => 'PhabricatorRepositoryEngine',
|
'PhabricatorRepositoryRefEngine' => 'PhabricatorRepositoryEngine',
|
||||||
'PhabricatorRepositoryRepositoryPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorRepositoryRepositoryPHIDType' => 'PhabricatorPHIDType',
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorRepositoryRefCursorPHIDType
|
||||||
|
extends PhabricatorPHIDType {
|
||||||
|
|
||||||
|
const TYPECONST = 'RREF';
|
||||||
|
|
||||||
|
public function getTypeName() {
|
||||||
|
return pht('Repository Ref');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newObject() {
|
||||||
|
return new PhabricatorRepositoryRefCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPHIDTypeApplicationClass() {
|
||||||
|
return 'PhabricatorDiffusionApplication';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildQueryForObjects(
|
||||||
|
PhabricatorObjectQuery $query,
|
||||||
|
array $phids) {
|
||||||
|
|
||||||
|
return id(new PhabricatorRepositoryRefCursorQuery())
|
||||||
|
->withPHIDs($phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadHandles(
|
||||||
|
PhabricatorHandleQuery $query,
|
||||||
|
array $handles,
|
||||||
|
array $objects) {
|
||||||
|
|
||||||
|
foreach ($handles as $phid => $handle) {
|
||||||
|
$ref = $objects[$phid];
|
||||||
|
|
||||||
|
$name = $ref->getRefName();
|
||||||
|
|
||||||
|
$handle->setName($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,10 +3,22 @@
|
||||||
final class PhabricatorRepositoryRefCursorQuery
|
final class PhabricatorRepositoryRefCursorQuery
|
||||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
|
private $ids;
|
||||||
|
private $phids;
|
||||||
private $repositoryPHIDs;
|
private $repositoryPHIDs;
|
||||||
private $refTypes;
|
private $refTypes;
|
||||||
private $refNames;
|
private $refNames;
|
||||||
|
|
||||||
|
public function withIDs(array $ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withPHIDs(array $phids) {
|
||||||
|
$this->phids = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withRepositoryPHIDs(array $phids) {
|
public function withRepositoryPHIDs(array $phids) {
|
||||||
$this->repositoryPHIDs = $phids;
|
$this->repositoryPHIDs = $phids;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -22,19 +34,12 @@ final class PhabricatorRepositoryRefCursorQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newResultObject() {
|
||||||
|
return new PhabricatorRepositoryRefCursor();
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = new PhabricatorRepositoryRefCursor();
|
return $this->loadStandardPage($this->newResultObject());
|
||||||
$conn_r = $table->establishConnection('r');
|
|
||||||
|
|
||||||
$data = queryfx_all(
|
|
||||||
$conn_r,
|
|
||||||
'SELECT * FROM %T r %Q %Q %Q',
|
|
||||||
$table->getTableName(),
|
|
||||||
$this->buildWhereClause($conn_r),
|
|
||||||
$this->buildOrderClause($conn_r),
|
|
||||||
$this->buildLimitClause($conn_r));
|
|
||||||
|
|
||||||
return $table->loadAllFromArray($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function willFilterPage(array $refs) {
|
protected function willFilterPage(array $refs) {
|
||||||
|
@ -50,6 +55,7 @@ final class PhabricatorRepositoryRefCursorQuery
|
||||||
foreach ($refs as $key => $ref) {
|
foreach ($refs as $key => $ref) {
|
||||||
$repository = idx($repositories, $ref->getRepositoryPHID());
|
$repository = idx($repositories, $ref->getRepositoryPHID());
|
||||||
if (!$repository) {
|
if (!$repository) {
|
||||||
|
$this->didRejectResult($ref);
|
||||||
unset($refs[$key]);
|
unset($refs[$key]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -59,19 +65,33 @@ final class PhabricatorRepositoryRefCursorQuery
|
||||||
return $refs;
|
return $refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = array();
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
|
if ($this->ids !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'id IN (%Ld)',
|
||||||
|
$this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->phids !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'phid IN (%Ls)',
|
||||||
|
$this->phids);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->repositoryPHIDs !== null) {
|
if ($this->repositoryPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'repositoryPHID IN (%Ls)',
|
'repositoryPHID IN (%Ls)',
|
||||||
$this->repositoryPHIDs);
|
$this->repositoryPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->refTypes !== null) {
|
if ($this->refTypes !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'refType IN (%Ls)',
|
'refType IN (%Ls)',
|
||||||
$this->refTypes);
|
$this->refTypes);
|
||||||
}
|
}
|
||||||
|
@ -83,14 +103,12 @@ final class PhabricatorRepositoryRefCursorQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'refNameHash IN (%Ls)',
|
'refNameHash IN (%Ls)',
|
||||||
$name_hashes);
|
$name_hashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
return $where;
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
* out how a repository has changed when we discover new commits or branch
|
* out how a repository has changed when we discover new commits or branch
|
||||||
* heads.
|
* heads.
|
||||||
*/
|
*/
|
||||||
final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
final class PhabricatorRepositoryRefCursor
|
||||||
|
extends PhabricatorRepositoryDAO
|
||||||
implements PhabricatorPolicyInterface {
|
implements PhabricatorPolicyInterface {
|
||||||
|
|
||||||
const TYPE_BRANCH = 'branch';
|
const TYPE_BRANCH = 'branch';
|
||||||
|
@ -25,6 +26,7 @@ final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
||||||
protected function getConfiguration() {
|
protected function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_TIMESTAMPS => false,
|
self::CONFIG_TIMESTAMPS => false,
|
||||||
|
self::CONFIG_AUX_PHID => true,
|
||||||
self::CONFIG_BINARY => array(
|
self::CONFIG_BINARY => array(
|
||||||
'refNameRaw' => true,
|
'refNameRaw' => true,
|
||||||
),
|
),
|
||||||
|
@ -32,9 +34,6 @@ final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
||||||
'refType' => 'text32',
|
'refType' => 'text32',
|
||||||
'refNameHash' => 'bytes12',
|
'refNameHash' => 'bytes12',
|
||||||
'commitIdentifier' => 'text40',
|
'commitIdentifier' => 'text40',
|
||||||
|
|
||||||
// T6203/NULLABILITY
|
|
||||||
// This probably should not be nullable; refNameRaw is not nullable.
|
|
||||||
'refNameEncoding' => 'text16?',
|
'refNameEncoding' => 'text16?',
|
||||||
'isClosed' => 'bool',
|
'isClosed' => 'bool',
|
||||||
),
|
),
|
||||||
|
@ -46,6 +45,11 @@ final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generatePHID() {
|
||||||
|
return PhabricatorPHID::generateNewPHID(
|
||||||
|
PhabricatorRepositoryRefCursorPHIDType::TYPECONST);
|
||||||
|
}
|
||||||
|
|
||||||
public function getRefName() {
|
public function getRefName() {
|
||||||
return $this->getUTF8StringFromStorage(
|
return $this->getUTF8StringFromStorage(
|
||||||
$this->getRefNameRaw(),
|
$this->getRefNameRaw(),
|
||||||
|
|
Loading…
Reference in a new issue