@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.

Clean up Diffusion branch query a bit

Summary:
Ref T2716.

- Serve from `DiffusionCommitQuery`, not `PhabricatorAuditCommitQuery` (which should probably die).
- Fix logic for `limit`, which incorrectly failed to display the "Showing %d branches." text.
- Clean up things a touch.
- I didn't end up actually needing `needCommitData()`, but left it in there since I think it will be needed soon.
- Removed a "TODO" because I don't remember what "etc etc" means.

Test Plan: Looked at branches in several repositories.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2716

Differential Revision: https://secure.phabricator.com/D7451

+86 -52
+46 -45
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 198 198 } 199 199 200 200 private function buildBranchListTable(DiffusionRequest $drequest) { 201 - if ($drequest->getBranch() !== null) { 202 - $limit = 15; 201 + $viewer = $this->getRequest()->getUser(); 203 202 204 - $branches = DiffusionBranchInformation::newFromConduit( 205 - $this->callConduitWithDiffusionRequest( 206 - 'diffusion.branchquery', 207 - array( 208 - 'limit' => $limit 209 - ))); 210 - if (!$branches) { 211 - return null; 212 - } 203 + if ($drequest->getBranch() === null) { 204 + return null; 205 + } 213 206 214 - $more_branches = (count($branches) > $limit); 215 - $branches = array_slice($branches, 0, $limit); 207 + $limit = 15; 216 208 217 - $commits = id(new PhabricatorAuditCommitQuery()) 218 - ->withIdentifiers( 219 - $drequest->getRepository()->getID(), 220 - mpull($branches, 'getHeadCommitIdentifier')) 221 - ->needCommitData(true) 222 - ->execute(); 209 + $branches = DiffusionBranchInformation::newFromConduit( 210 + $this->callConduitWithDiffusionRequest( 211 + 'diffusion.branchquery', 212 + array( 213 + 'limit' => $limit + 1, 214 + ))); 215 + if (!$branches) { 216 + return null; 217 + } 218 + 219 + $more_branches = (count($branches) > $limit); 220 + $branches = array_slice($branches, 0, $limit); 223 221 224 - $table = new DiffusionBranchTableView(); 225 - $table->setDiffusionRequest($drequest); 226 - $table->setBranches($branches); 227 - $table->setCommits($commits); 228 - $table->setUser($this->getRequest()->getUser()); 222 + $commits = id(new DiffusionCommitQuery()) 223 + ->setViewer($viewer) 224 + ->withIdentifiers(mpull($branches, 'getHeadCommitIdentifier')) 225 + ->withRepositoryIDs(array($drequest->getRepository()->getID())) 226 + ->execute(); 229 227 230 - $panel = new AphrontPanelView(); 231 - $panel->setHeader(pht('Branches')); 232 - $panel->setNoBackground(); 228 + $table = new DiffusionBranchTableView(); 229 + $table->setDiffusionRequest($drequest); 230 + $table->setBranches($branches); 231 + $table->setCommits($commits); 232 + $table->setUser($this->getRequest()->getUser()); 233 233 234 - if ($more_branches) { 235 - $panel->setCaption(pht('Showing %d branches.', $limit)); 236 - } 234 + $panel = new AphrontPanelView(); 235 + $panel->setHeader(pht('Branches')); 236 + $panel->setNoBackground(); 237 237 238 - $panel->addButton( 239 - phutil_tag( 240 - 'a', 241 - array( 242 - 'href' => $drequest->generateURI( 243 - array( 244 - 'action' => 'branches', 245 - )), 246 - 'class' => 'grey button', 247 - ), 248 - pht("Show All Branches \xC2\xBB"))); 238 + if ($more_branches) { 239 + $panel->setCaption(pht('Showing %d branches.', $limit)); 240 + } 249 241 250 - $panel->appendChild($table); 242 + $panel->addButton( 243 + phutil_tag( 244 + 'a', 245 + array( 246 + 'href' => $drequest->generateURI( 247 + array( 248 + 'action' => 'branches', 249 + )), 250 + 'class' => 'grey button', 251 + ), 252 + pht("Show All Branches \xC2\xBB"))); 251 253 252 - return $panel; 253 - } 254 + $panel->appendChild($table); 254 255 255 - return null; 256 + return $panel; 256 257 } 257 258 258 259 private function buildTagListTable(DiffusionRequest $drequest) {
+37 -1
src/applications/diffusion/query/DiffusionCommitQuery.php
··· 8 8 private $phids; 9 9 private $defaultRepository; 10 10 private $identifierMap; 11 + private $repositoryIDs; 12 + 13 + private $needCommitData; 11 14 12 15 /** 13 16 * Load commits by partial or full identifiers, e.g. "rXab82393", "rX1234", ··· 34 37 return $this; 35 38 } 36 39 40 + public function withRepositoryIDs(array $repository_ids) { 41 + $this->repositoryIDs = $repository_ids; 42 + return $this; 43 + } 44 + 37 45 public function withIDs(array $ids) { 38 46 $this->ids = $ids; 39 47 return $this; ··· 44 52 return $this; 45 53 } 46 54 55 + public function needCommitData($need) { 56 + $this->needCommitData = $need; 57 + return $this; 58 + } 59 + 47 60 public function getIdentifierMap() { 48 61 if ($this->identifierMap === null) { 49 62 throw new Exception( ··· 71 84 return $table->loadAllFromArray($data); 72 85 } 73 86 74 - public function willFilterPage(array $commits) { 87 + protected function willFilterPage(array $commits) { 75 88 $repository_ids = mpull($commits, 'getRepositoryID', 'getRepositoryID'); 76 89 $repos = id(new PhabricatorRepositoryQuery()) 77 90 ->setViewer($this->getViewer()) ··· 131 144 return $commits; 132 145 } 133 146 147 + protected function didFilterPage(array $commits) { 148 + 149 + if ($this->needCommitData) { 150 + $data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( 151 + 'commitID in (%Ld)', 152 + mpull($commits, 'getID')); 153 + $data = mpull($data, null, 'getCommitID'); 154 + foreach ($commits as $commit) { 155 + $commit_data = idx($data, $commit->getID()); 156 + $commit->attachCommitData($commit_data); 157 + } 158 + } 159 + 160 + return $commits; 161 + } 162 + 134 163 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 135 164 $where = array(); 136 165 ··· 235 264 $conn_r, 236 265 'phid IN (%Ls)', 237 266 $this->phids); 267 + } 268 + 269 + if ($this->repositoryIDs) { 270 + $where[] = qsprintf( 271 + $conn_r, 272 + 'repositoryID IN (%Ld)', 273 + $this->repositoryIDs); 238 274 } 239 275 240 276 return $this->formatWhereClause($where);
+1 -5
src/applications/diffusion/view/DiffusionBranchTableView.php
··· 25 25 foreach ($this->branches as $branch) { 26 26 $commit = idx($this->commits, $branch->getHeadCommitIdentifier()); 27 27 if ($commit) { 28 - $details = $commit->getCommitData()->getCommitMessage(); 29 - $details = idx(explode("\n", $details), 0); 30 - $details = substr($details, 0, 80); 31 - 28 + $details = $commit->getSummary(); 32 29 $datetime = phabricator_datetime($commit->getEpoch(), $this->user); 33 30 } else { 34 31 $datetime = null; ··· 61 58 $branch->getHeadCommitIdentifier()), 62 59 $datetime, 63 60 AphrontTableView::renderSingleDisplayLine($details), 64 - // TODO: etc etc 65 61 ); 66 62 if ($branch->getName() == $current_branch) { 67 63 $rowc[] = 'highlighted';
+2 -1
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 81 81 $this->getID()); 82 82 } 83 83 84 - public function attachCommitData(PhabricatorRepositoryCommitData $data) { 84 + public function attachCommitData( 85 + PhabricatorRepositoryCommitData $data = null) { 85 86 $this->commitData = $data; 86 87 return $this; 87 88 }