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

Separate repository mirroring into an Engine and provide `bin/repository mirror`

Summary:
Ref T4338. Currently, there's no diagnostic command to execute mirroring (so I can't give users an easy command to run), and it's roughly the last piece of real logic left in the PullLocal daemon.

Separate mirroring out, and provide `bin/repository mirror`.

Test Plan:
- Ran `bin/repository mirror` to mirror a repository.
- Ran PullLocalDaemon and verified it also continued mirroring normally.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4338

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

+121 -44
+4
src/__phutil_library_map__.php
··· 1860 1860 'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php', 1861 1861 'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php', 1862 1862 'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php', 1863 + 'PhabricatorRepositoryManagementMirrorWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php', 1863 1864 'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php', 1864 1865 'PhabricatorRepositoryManagementRefsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementRefsWorkflow.php', 1865 1866 'PhabricatorRepositoryManagementWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementWorkflow.php', 1866 1867 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php', 1867 1868 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php', 1868 1869 'PhabricatorRepositoryMirror' => 'applications/repository/storage/PhabricatorRepositoryMirror.php', 1870 + 'PhabricatorRepositoryMirrorEngine' => 'applications/repository/engine/PhabricatorRepositoryMirrorEngine.php', 1869 1871 'PhabricatorRepositoryMirrorQuery' => 'applications/repository/query/PhabricatorRepositoryMirrorQuery.php', 1870 1872 'PhabricatorRepositoryPHIDTypeArcanistProject' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php', 1871 1873 'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php', ··· 4539 4541 'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 4540 4542 'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 4541 4543 'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 4544 + 'PhabricatorRepositoryManagementMirrorWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 4542 4545 'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 4543 4546 'PhabricatorRepositoryManagementRefsWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 4544 4547 'PhabricatorRepositoryManagementWorkflow' => 'PhabricatorManagementWorkflow', ··· 4549 4552 0 => 'PhabricatorRepositoryDAO', 4550 4553 1 => 'PhabricatorPolicyInterface', 4551 4554 ), 4555 + 'PhabricatorRepositoryMirrorEngine' => 'PhabricatorRepositoryEngine', 4552 4556 'PhabricatorRepositoryMirrorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4553 4557 'PhabricatorRepositoryPHIDTypeArcanistProject' => 'PhabricatorPHIDType', 4554 4558 'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType',
+9 -44
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
··· 141 141 null); 142 142 $this->discoverRepository($repository); 143 143 $this->updateRepositoryRefs($repository); 144 + $this->mirrorRepository($repository); 144 145 $repository->writeStatusMessage( 145 146 PhabricatorRepositoryStatusMessage::TYPE_FETCH, 146 147 PhabricatorRepositoryStatusMessage::CODE_OKAY); ··· 229 230 230 231 $this->checkIfRepositoryIsFullyImported($repository); 231 232 233 + return (bool)count($refs); 234 + } 235 + 236 + private function mirrorRepository(PhabricatorRepository $repository) { 232 237 try { 233 - $this->pushToMirrors($repository); 238 + id(new PhabricatorRepositoryMirrorEngine()) 239 + ->setRepository($repository) 240 + ->pushToMirrors(); 234 241 } catch (Exception $ex) { 235 242 // TODO: We should report these into the UI properly, but for 236 243 // now just complain. These errors are much less severe than 237 244 // pull errors. 238 245 $proxy = new PhutilProxyException( 239 246 pht( 240 - 'Error while pushing "%s" repository to a mirror.', 247 + 'Error while pushing "%s" repository to mirrors.', 241 248 $repository->getCallsign()), 242 249 $ex); 243 250 phlog($proxy); 244 251 } 245 - 246 - return (bool)count($refs); 247 252 } 248 253 249 254 private function updateRepositoryRefs(PhabricatorRepository $repository) { ··· 299 304 $repository->saveTransaction(); 300 305 } 301 306 302 - 303 - private function pushToMirrors(PhabricatorRepository $repository) { 304 - if (!$repository->canMirror()) { 305 - return; 306 - } 307 - 308 - $mirrors = id(new PhabricatorRepositoryMirrorQuery()) 309 - ->setViewer($this->getViewer()) 310 - ->withRepositoryPHIDs(array($repository->getPHID())) 311 - ->execute(); 312 - 313 - // TODO: This is a little bit janky, but we don't have first-class 314 - // infrastructure for running remote commands against an arbitrary remote 315 - // right now. Just make an emphemeral copy of the repository and muck with 316 - // it a little bit. In the medium term, we should pull this command stuff 317 - // out and use it here and for "Land to ...". 318 - 319 - $proxy = clone $repository; 320 - $proxy->makeEphemeral(); 321 - 322 - $proxy->setDetail('hosting-enabled', false); 323 - foreach ($mirrors as $mirror) { 324 - $proxy->setDetail('remote-uri', $mirror->getRemoteURI()); 325 - $proxy->setCredentialPHID($mirror->getCredentialPHID()); 326 - 327 - $this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI())); 328 - 329 - if (!$proxy->isGit()) { 330 - throw new Exception('Unsupported VCS!'); 331 - } 332 - 333 - $future = $proxy->getRemoteCommandFuture( 334 - 'push --verbose --mirror -- %P', 335 - $proxy->getRemoteURIEnvelope()); 336 - 337 - $future 338 - ->setCWD($proxy->getLocalPath()) 339 - ->resolvex(); 340 - } 341 - } 342 307 }
+5
src/applications/repository/engine/PhabricatorRepositoryEngine.php
··· 47 47 } 48 48 49 49 50 + public function getViewer() { 51 + return PhabricatorUser::getOmnipotentUser(); 52 + } 53 + 54 + 50 55 /** 51 56 * @task internal 52 57 */
+51
src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php
··· 1 + <?php 2 + 3 + /** 4 + * Pushes a repository to its mirrors. 5 + */ 6 + final class PhabricatorRepositoryMirrorEngine 7 + extends PhabricatorRepositoryEngine { 8 + 9 + public function pushToMirrors() { 10 + $repository = $this->getRepository(); 11 + 12 + if (!$repository->canMirror()) { 13 + return; 14 + } 15 + 16 + $mirrors = id(new PhabricatorRepositoryMirrorQuery()) 17 + ->setViewer($this->getViewer()) 18 + ->withRepositoryPHIDs(array($repository->getPHID())) 19 + ->execute(); 20 + 21 + // TODO: This is a little bit janky, but we don't have first-class 22 + // infrastructure for running remote commands against an arbitrary remote 23 + // right now. Just make an emphemeral copy of the repository and muck with 24 + // it a little bit. In the medium term, we should pull this command stuff 25 + // out and use it here and for "Land to ...". 26 + 27 + $proxy = clone $repository; 28 + $proxy->makeEphemeral(); 29 + 30 + $proxy->setDetail('hosting-enabled', false); 31 + foreach ($mirrors as $mirror) { 32 + $proxy->setDetail('remote-uri', $mirror->getRemoteURI()); 33 + $proxy->setCredentialPHID($mirror->getCredentialPHID()); 34 + 35 + $this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI())); 36 + 37 + if (!$proxy->isGit()) { 38 + throw new Exception('Unsupported VCS!'); 39 + } 40 + 41 + $future = $proxy->getRemoteCommandFuture( 42 + 'push --verbose --mirror -- %P', 43 + $proxy->getRemoteURIEnvelope()); 44 + 45 + $future 46 + ->setCWD($proxy->getLocalPath()) 47 + ->resolvex(); 48 + } 49 + } 50 + 51 + }
+52
src/applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorRepositoryManagementMirrorWorkflow 4 + extends PhabricatorRepositoryManagementWorkflow { 5 + 6 + public function didConstruct() { 7 + $this 8 + ->setName('mirror') 9 + ->setExamples('**mirror** [__options__] __repository__ ...') 10 + ->setSynopsis( 11 + pht('Push __repository__, named by callsign, to mirrors.')) 12 + ->setArguments( 13 + array( 14 + array( 15 + 'name' => 'verbose', 16 + 'help' => pht('Show additional debugging information.'), 17 + ), 18 + array( 19 + 'name' => 'repos', 20 + 'wildcard' => true, 21 + ), 22 + )); 23 + } 24 + 25 + public function execute(PhutilArgumentParser $args) { 26 + $repos = $this->loadRepositories($args, 'repos'); 27 + 28 + if (!$repos) { 29 + throw new PhutilArgumentUsageException( 30 + pht( 31 + "Specify one or more repositories to push to mirrors, by ". 32 + "callsign.")); 33 + } 34 + 35 + $console = PhutilConsole::getConsole(); 36 + foreach ($repos as $repo) { 37 + $console->writeOut( 38 + "%s\n", 39 + pht('Pushing "%s" to mirrors...', $repo->getCallsign())); 40 + 41 + $engine = id(new PhabricatorRepositoryMirrorEngine()) 42 + ->setRepository($repo) 43 + ->setVerbose($args->getArg('verbose')) 44 + ->pushToMirrors(); 45 + } 46 + 47 + $console->writeOut("Done.\n"); 48 + 49 + return 0; 50 + } 51 + 52 + }