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

Show additional status information during repository import

Summary:
Ref T2350. Fixes T2231.

- Adds log flags around discovery.
- Adds message flags for "needs update". This is basically an out-of-band hint to the daemons that a repository should be pulled sooner than normal. We set the flag when users push a revision, and expose a Conduit method that `arc land` will be able to use.

Test Plan: See screenshots.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2350, T2231

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

+193 -7
+2
src/__phutil_library_map__.php
··· 159 159 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getrecentcommitsbypath_Method.php', 160 160 'ConduitAPI_diffusion_historyquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php', 161 161 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php', 162 + 'ConduitAPI_diffusion_looksoon_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_looksoon_Method.php', 162 163 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php', 163 164 'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php', 164 165 'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php', ··· 2366 2367 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPI_diffusion_Method', 2367 2368 'ConduitAPI_diffusion_historyquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2368 2369 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2370 + 'ConduitAPI_diffusion_looksoon_Method' => 'ConduitAPI_diffusion_Method', 2369 2371 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2370 2372 'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2371 2373 'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
+55
src/applications/diffusion/conduit/ConduitAPI_diffusion_looksoon_Method.php
··· 1 + <?php 2 + 3 + final class ConduitAPI_diffusion_looksoon_Method 4 + extends ConduitAPI_diffusion_Method { 5 + 6 + public function getMethodStatus() { 7 + return self::METHOD_STATUS_UNSTABLE; 8 + } 9 + 10 + public function getMethodDescription() { 11 + return pht( 12 + 'Advises Phabricator to look for new commits in a repository as soon '. 13 + 'as possible. This advice is most useful if you have just pushed new '. 14 + 'commits to that repository.'); 15 + } 16 + 17 + public function defineReturnType() { 18 + return 'void'; 19 + } 20 + 21 + public function defineParamTypes() { 22 + return array( 23 + 'callsigns' => 'required list<string>', 24 + 'urgency' => 'optional string', 25 + ); 26 + } 27 + 28 + public function defineErrorTypes() { 29 + return array(); 30 + } 31 + 32 + protected function execute(ConduitAPIRequest $request) { 33 + // NOTE: The "urgency" parameter does nothing, it is just a hilarious joke 34 + // which exemplifies the boundless clever wit of this project. 35 + 36 + $callsigns = $request->getValue('callsigns'); 37 + if (!$callsigns) { 38 + return null; 39 + } 40 + 41 + $repositories = id(new PhabricatorRepositoryQuery()) 42 + ->setViewer($request->getUser()) 43 + ->withCallsigns($callsigns) 44 + ->execute(); 45 + 46 + foreach ($repositories as $repository) { 47 + $repository->writeStatusMessage( 48 + PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, 49 + PhabricatorRepositoryStatusMessage::CODE_OKAY); 50 + } 51 + 52 + return null; 53 + } 54 + 55 + }
+13 -4
src/applications/diffusion/controller/DiffusionController.php
··· 140 140 141 141 switch ($repository->getVersionControlSystem()) { 142 142 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 143 - return $this->serveGitRequest($repository); 143 + $result = $this->serveGitRequest($repository); 144 144 default: 145 + $result = new PhabricatorVCSResponse( 146 + 999, 147 + pht('TODO: Implement meaningful responses.')); 145 148 break; 146 149 } 147 150 148 - return new PhabricatorVCSResponse( 149 - 999, 150 - pht('TODO: Implement meaningful responses.')); 151 + $code = $result->getHTTPResponseCode(); 152 + 153 + if ($is_push && ($code == 200)) { 154 + $repository->writeStatusMessage( 155 + PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, 156 + PhabricatorRepositoryStatusMessage::CODE_OKAY); 157 + } 158 + 159 + return $result; 151 160 } 152 161 153 162 private function isReadOnlyRequest(
+89 -1
src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php
··· 563 563 private function buildRepositoryStatus( 564 564 PhabricatorRepository $repository) { 565 565 566 + $viewer = $this->getRequest()->getUser(); 567 + 566 568 $view = new PHUIStatusListView(); 567 569 568 570 $messages = id(new PhabricatorRepositoryStatusMessage()) ··· 696 698 id(new PHUIStatusItemView()) 697 699 ->setIcon('time-green') 698 700 ->setTarget(pht('Initializing Working Copy')) 699 - ->setNote(pht('Daemons are initilizing the working copy.'))); 701 + ->setNote(pht('Daemons are initializing the working copy.'))); 700 702 return $view; 701 703 default: 702 704 $view->addItem( ··· 715 717 pht('Waiting for daemons to build a working copy.'))); 716 718 return $view; 717 719 } 720 + } 721 + 722 + $message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH); 723 + if ($message) { 724 + switch ($message->getStatusCode()) { 725 + case PhabricatorRepositoryStatusMessage::CODE_ERROR: 726 + $view->addItem( 727 + id(new PHUIStatusItemView()) 728 + ->setIcon('warning-red') 729 + ->setTarget(pht('Update Error')) 730 + ->setNote($message->getParameter('message'))); 731 + return $view; 732 + case PhabricatorRepositoryStatusMessage::CODE_OKAY: 733 + $view->addItem( 734 + id(new PHUIStatusItemView()) 735 + ->setIcon('accept-green') 736 + ->setTarget(pht('Updates OK')) 737 + ->setNote( 738 + pht( 739 + 'Last updated %s.', 740 + phabricator_datetime($message->getEpoch(), $viewer)))); 741 + break; 742 + } 743 + } else { 744 + $view->addItem( 745 + id(new PHUIStatusItemView()) 746 + ->setIcon('time-orange') 747 + ->setTarget(pht('Waiting For Update')) 748 + ->setNote( 749 + pht('Waiting for daemons to read updates.'))); 750 + } 751 + 752 + if ($repository->isImporting()) { 753 + $progress = queryfx_all( 754 + $repository->establishConnection('r'), 755 + 'SELECT importStatus, count(*) N FROM %T WHERE repositoryID = %d 756 + GROUP BY importStatus', 757 + id(new PhabricatorRepositoryCommit())->getTableName(), 758 + $repository->getID()); 759 + 760 + $done = 0; 761 + $total = 0; 762 + foreach ($progress as $row) { 763 + $total += $row['N'] * 4; 764 + $status = $row['importStatus']; 765 + if ($status & PhabricatorRepositoryCommit::IMPORTED_MESSAGE) { 766 + $done += $row['N']; 767 + } 768 + if ($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE) { 769 + $done += $row['N']; 770 + } 771 + if ($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS) { 772 + $done += $row['N']; 773 + } 774 + if ($status & PhabricatorRepositoryCommit::IMPORTED_HERALD) { 775 + $done += $row['N']; 776 + } 777 + } 778 + 779 + if ($total) { 780 + $percentage = 100 * ($done / $total); 781 + } else { 782 + $percentage = 0; 783 + } 784 + 785 + $percentage = sprintf('%.1f%%', $percentage); 786 + 787 + $view->addItem( 788 + id(new PHUIStatusItemView()) 789 + ->setIcon('time-green') 790 + ->setTarget(pht('Importing')) 791 + ->setNote( 792 + pht('%s Complete', $percentage))); 793 + } else { 794 + $view->addItem( 795 + id(new PHUIStatusItemView()) 796 + ->setIcon('accept-green') 797 + ->setTarget(pht('Fully Imported'))); 798 + } 799 + 800 + if (idx($messages, PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE)) { 801 + $view->addItem( 802 + id(new PHUIStatusItemView()) 803 + ->setIcon('up') 804 + ->setTarget(pht('Prioritized')) 805 + ->setNote(pht('This repository will be updated soon.'))); 718 806 } 719 807 720 808 return $view;
+9 -1
src/applications/diffusion/ssh/DiffusionSSHGitReceivePackWorkflow.php
··· 28 28 $future = new ExecFuture( 29 29 'git-receive-pack %s', 30 30 $repository->getLocalPath()); 31 - return $this->passthruIO($future); 31 + $err = $this->passthruIO($future); 32 + 33 + if (!$err) { 34 + $repository->writeStatusMessage( 35 + PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, 36 + PhabricatorRepositoryStatusMessage::CODE_OKAY); 37 + } 38 + 39 + return $err; 32 40 } 33 41 34 42 }
+25 -1
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
··· 92 92 shuffle($repositories); 93 93 $repositories = mpull($repositories, null, 'getID'); 94 94 95 + // If any repositories have the NEEDS_UPDATE flag set, pull them 96 + // as soon as possible. 97 + $type_need_update = PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE; 98 + $need_update_messages = id(new PhabricatorRepositoryStatusMessage()) 99 + ->loadAllWhere('statusType = %s', $type_need_update); 100 + foreach ($need_update_messages as $message) { 101 + $retry_after[$message->getRepositoryID()] = time(); 102 + } 103 + 95 104 // If any repositories were deleted, remove them from the retry timer map 96 105 // so we don't end up with a retry timer that never gets updated and 97 106 // causes us to sleep for the minimum amount of time. ··· 135 144 $lock = PhabricatorGlobalLock::newLock($lock_name); 136 145 $lock->lock(); 137 146 147 + $repository->writeStatusMessage( 148 + PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, 149 + null); 150 + 138 151 try { 139 152 $this->discoverRepository($repository); 153 + $repository->writeStatusMessage( 154 + PhabricatorRepositoryStatusMessage::TYPE_FETCH, 155 + PhabricatorRepositoryStatusMessage::CODE_OKAY); 140 156 } catch (Exception $ex) { 157 + $repository->writeStatusMessage( 158 + PhabricatorRepositoryStatusMessage::TYPE_FETCH, 159 + PhabricatorRepositoryStatusMessage::CODE_ERROR, 160 + array( 161 + 'message' => pht( 162 + 'Error updating working copy: %s', $ex->getMessage()), 163 + )); 141 164 $lock->unlock(); 142 165 throw $ex; 143 166 } ··· 483 506 // Look for any commit which hasn't imported. 484 507 $unparsed_commit = queryfx_one( 485 508 $repository->establishConnection('r'), 486 - 'SELECT * FROM %T WHERE repositoryID = %d AND importStatus != %d', 509 + 'SELECT * FROM %T WHERE repositoryID = %d AND importStatus != %d 510 + LIMIT 1', 487 511 id(new PhabricatorRepositoryCommit())->getTableName(), 488 512 $repository->getID(), 489 513 PhabricatorRepositoryCommit::IMPORTED_ALL);