@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+109 -24
+2
resources/sql/autopatches/20151210.land.1.refphid.sql
··· 1 + ALTER TABLE {$NAMESPACE}_repository.repository_refcursor 2 + ADD phid VARBINARY(64) NOT NULL AFTER id;
+17
resources/sql/autopatches/20151210.land.2.refphid.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorRepositoryRefCursor(); 4 + $conn_w = $table->establishConnection('w'); 5 + 6 + foreach (new LiskMigrationIterator($table) as $cursor) { 7 + if (strlen($cursor->getPHID())) { 8 + continue; 9 + } 10 + 11 + queryfx( 12 + $conn_w, 13 + 'UPDATE %T SET phid = %s WHERE id = %d', 14 + $table->getTableName(), 15 + $table->generatePHID(), 16 + $cursor->getID()); 17 + }
+2
src/__phutil_library_map__.php
··· 2907 2907 'PhabricatorRepositoryPushReplyHandler' => 'applications/repository/mail/PhabricatorRepositoryPushReplyHandler.php', 2908 2908 'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php', 2909 2909 'PhabricatorRepositoryRefCursor' => 'applications/repository/storage/PhabricatorRepositoryRefCursor.php', 2910 + 'PhabricatorRepositoryRefCursorPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRefCursorPHIDType.php', 2910 2911 'PhabricatorRepositoryRefCursorQuery' => 'applications/repository/query/PhabricatorRepositoryRefCursorQuery.php', 2911 2912 'PhabricatorRepositoryRefEngine' => 'applications/repository/engine/PhabricatorRepositoryRefEngine.php', 2912 2913 'PhabricatorRepositoryRepositoryPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php', ··· 7199 7200 'PhabricatorRepositoryDAO', 7200 7201 'PhabricatorPolicyInterface', 7201 7202 ), 7203 + 'PhabricatorRepositoryRefCursorPHIDType' => 'PhabricatorPHIDType', 7202 7204 'PhabricatorRepositoryRefCursorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7203 7205 'PhabricatorRepositoryRefEngine' => 'PhabricatorRepositoryEngine', 7204 7206 'PhabricatorRepositoryRepositoryPHIDType' => 'PhabricatorPHIDType',
+42
src/applications/repository/phid/PhabricatorRepositoryRefCursorPHIDType.php
··· 1 + <?php 2 + 3 + final class PhabricatorRepositoryRefCursorPHIDType 4 + extends PhabricatorPHIDType { 5 + 6 + const TYPECONST = 'RREF'; 7 + 8 + public function getTypeName() { 9 + return pht('Repository Ref'); 10 + } 11 + 12 + public function newObject() { 13 + return new PhabricatorRepositoryRefCursor(); 14 + } 15 + 16 + public function getPHIDTypeApplicationClass() { 17 + return 'PhabricatorDiffusionApplication'; 18 + } 19 + 20 + protected function buildQueryForObjects( 21 + PhabricatorObjectQuery $query, 22 + array $phids) { 23 + 24 + return id(new PhabricatorRepositoryRefCursorQuery()) 25 + ->withPHIDs($phids); 26 + } 27 + 28 + public function loadHandles( 29 + PhabricatorHandleQuery $query, 30 + array $handles, 31 + array $objects) { 32 + 33 + foreach ($handles as $phid => $handle) { 34 + $ref = $objects[$phid]; 35 + 36 + $name = $ref->getRefName(); 37 + 38 + $handle->setName($name); 39 + } 40 + } 41 + 42 + }
+38 -20
src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
··· 3 3 final class PhabricatorRepositoryRefCursorQuery 4 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 5 6 + private $ids; 7 + private $phids; 6 8 private $repositoryPHIDs; 7 9 private $refTypes; 8 10 private $refNames; 9 11 12 + public function withIDs(array $ids) { 13 + $this->ids = $ids; 14 + return $this; 15 + } 16 + 17 + public function withPHIDs(array $phids) { 18 + $this->phids = $phids; 19 + return $this; 20 + } 21 + 10 22 public function withRepositoryPHIDs(array $phids) { 11 23 $this->repositoryPHIDs = $phids; 12 24 return $this; ··· 22 34 return $this; 23 35 } 24 36 25 - protected function loadPage() { 26 - $table = new PhabricatorRepositoryRefCursor(); 27 - $conn_r = $table->establishConnection('r'); 37 + public function newResultObject() { 38 + return new PhabricatorRepositoryRefCursor(); 39 + } 28 40 29 - $data = queryfx_all( 30 - $conn_r, 31 - 'SELECT * FROM %T r %Q %Q %Q', 32 - $table->getTableName(), 33 - $this->buildWhereClause($conn_r), 34 - $this->buildOrderClause($conn_r), 35 - $this->buildLimitClause($conn_r)); 36 - 37 - return $table->loadAllFromArray($data); 41 + protected function loadPage() { 42 + return $this->loadStandardPage($this->newResultObject()); 38 43 } 39 44 40 45 protected function willFilterPage(array $refs) { ··· 50 55 foreach ($refs as $key => $ref) { 51 56 $repository = idx($repositories, $ref->getRepositoryPHID()); 52 57 if (!$repository) { 58 + $this->didRejectResult($ref); 53 59 unset($refs[$key]); 54 60 continue; 55 61 } ··· 59 65 return $refs; 60 66 } 61 67 62 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 63 - $where = array(); 68 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 69 + $where = parent::buildWhereClauseParts($conn); 70 + 71 + if ($this->ids !== null) { 72 + $where[] = qsprintf( 73 + $conn, 74 + 'id IN (%Ld)', 75 + $this->ids); 76 + } 77 + 78 + if ($this->phids !== null) { 79 + $where[] = qsprintf( 80 + $conn, 81 + 'phid IN (%Ls)', 82 + $this->phids); 83 + } 64 84 65 85 if ($this->repositoryPHIDs !== null) { 66 86 $where[] = qsprintf( 67 - $conn_r, 87 + $conn, 68 88 'repositoryPHID IN (%Ls)', 69 89 $this->repositoryPHIDs); 70 90 } 71 91 72 92 if ($this->refTypes !== null) { 73 93 $where[] = qsprintf( 74 - $conn_r, 94 + $conn, 75 95 'refType IN (%Ls)', 76 96 $this->refTypes); 77 97 } ··· 83 103 } 84 104 85 105 $where[] = qsprintf( 86 - $conn_r, 106 + $conn, 87 107 'refNameHash IN (%Ls)', 88 108 $name_hashes); 89 109 } 90 110 91 - $where[] = $this->buildPagingClause($conn_r); 92 - 93 - return $this->formatWhereClause($where); 111 + return $where; 94 112 } 95 113 96 114 public function getQueryApplicationClass() {
+8 -4
src/applications/repository/storage/PhabricatorRepositoryRefCursor.php
··· 5 5 * out how a repository has changed when we discover new commits or branch 6 6 * heads. 7 7 */ 8 - final class PhabricatorRepositoryRefCursor extends PhabricatorRepositoryDAO 8 + final class PhabricatorRepositoryRefCursor 9 + extends PhabricatorRepositoryDAO 9 10 implements PhabricatorPolicyInterface { 10 11 11 12 const TYPE_BRANCH = 'branch'; ··· 25 26 protected function getConfiguration() { 26 27 return array( 27 28 self::CONFIG_TIMESTAMPS => false, 29 + self::CONFIG_AUX_PHID => true, 28 30 self::CONFIG_BINARY => array( 29 31 'refNameRaw' => true, 30 32 ), ··· 32 34 'refType' => 'text32', 33 35 'refNameHash' => 'bytes12', 34 36 'commitIdentifier' => 'text40', 35 - 36 - // T6203/NULLABILITY 37 - // This probably should not be nullable; refNameRaw is not nullable. 38 37 'refNameEncoding' => 'text16?', 39 38 'isClosed' => 'bool', 40 39 ), ··· 44 43 ), 45 44 ), 46 45 ) + parent::getConfiguration(); 46 + } 47 + 48 + public function generatePHID() { 49 + return PhabricatorPHID::generateNewPHID( 50 + PhabricatorRepositoryRefCursorPHIDType::TYPECONST); 47 51 } 48 52 49 53 public function getRefName() {