Page MenuHomePhabricator

D8066.id.diff
No OneTemporary

D8066.id.diff

Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -1860,12 +1860,14 @@
'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php',
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php',
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php',
+ 'PhabricatorRepositoryManagementMirrorWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php',
'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php',
'PhabricatorRepositoryManagementRefsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementRefsWorkflow.php',
'PhabricatorRepositoryManagementWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementWorkflow.php',
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php',
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php',
'PhabricatorRepositoryMirror' => 'applications/repository/storage/PhabricatorRepositoryMirror.php',
+ 'PhabricatorRepositoryMirrorEngine' => 'applications/repository/engine/PhabricatorRepositoryMirrorEngine.php',
'PhabricatorRepositoryMirrorQuery' => 'applications/repository/query/PhabricatorRepositoryMirrorQuery.php',
'PhabricatorRepositoryPHIDTypeArcanistProject' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php',
'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php',
@@ -4539,6 +4541,7 @@
'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
+ 'PhabricatorRepositoryManagementMirrorWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementRefsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementWorkflow' => 'PhabricatorManagementWorkflow',
@@ -4549,6 +4552,7 @@
0 => 'PhabricatorRepositoryDAO',
1 => 'PhabricatorPolicyInterface',
),
+ 'PhabricatorRepositoryMirrorEngine' => 'PhabricatorRepositoryEngine',
'PhabricatorRepositoryMirrorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorRepositoryPHIDTypeArcanistProject' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType',
Index: src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
===================================================================
--- src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
+++ src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
@@ -141,6 +141,7 @@
null);
$this->discoverRepository($repository);
$this->updateRepositoryRefs($repository);
+ $this->mirrorRepository($repository);
$repository->writeStatusMessage(
PhabricatorRepositoryStatusMessage::TYPE_FETCH,
PhabricatorRepositoryStatusMessage::CODE_OKAY);
@@ -229,21 +230,25 @@
$this->checkIfRepositoryIsFullyImported($repository);
+ return (bool)count($refs);
+ }
+
+ private function mirrorRepository(PhabricatorRepository $repository) {
try {
- $this->pushToMirrors($repository);
+ id(new PhabricatorRepositoryMirrorEngine())
+ ->setRepository($repository)
+ ->pushToMirrors();
} catch (Exception $ex) {
// TODO: We should report these into the UI properly, but for
// now just complain. These errors are much less severe than
// pull errors.
$proxy = new PhutilProxyException(
pht(
- 'Error while pushing "%s" repository to a mirror.',
+ 'Error while pushing "%s" repository to mirrors.',
$repository->getCallsign()),
$ex);
phlog($proxy);
}
-
- return (bool)count($refs);
}
private function updateRepositoryRefs(PhabricatorRepository $repository) {
@@ -299,44 +304,4 @@
$repository->saveTransaction();
}
-
- private function pushToMirrors(PhabricatorRepository $repository) {
- if (!$repository->canMirror()) {
- return;
- }
-
- $mirrors = id(new PhabricatorRepositoryMirrorQuery())
- ->setViewer($this->getViewer())
- ->withRepositoryPHIDs(array($repository->getPHID()))
- ->execute();
-
- // TODO: This is a little bit janky, but we don't have first-class
- // infrastructure for running remote commands against an arbitrary remote
- // right now. Just make an emphemeral copy of the repository and muck with
- // it a little bit. In the medium term, we should pull this command stuff
- // out and use it here and for "Land to ...".
-
- $proxy = clone $repository;
- $proxy->makeEphemeral();
-
- $proxy->setDetail('hosting-enabled', false);
- foreach ($mirrors as $mirror) {
- $proxy->setDetail('remote-uri', $mirror->getRemoteURI());
- $proxy->setCredentialPHID($mirror->getCredentialPHID());
-
- $this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI()));
-
- if (!$proxy->isGit()) {
- throw new Exception('Unsupported VCS!');
- }
-
- $future = $proxy->getRemoteCommandFuture(
- 'push --verbose --mirror -- %P',
- $proxy->getRemoteURIEnvelope());
-
- $future
- ->setCWD($proxy->getLocalPath())
- ->resolvex();
- }
- }
}
Index: src/applications/repository/engine/PhabricatorRepositoryEngine.php
===================================================================
--- src/applications/repository/engine/PhabricatorRepositoryEngine.php
+++ src/applications/repository/engine/PhabricatorRepositoryEngine.php
@@ -47,6 +47,11 @@
}
+ public function getViewer() {
+ return PhabricatorUser::getOmnipotentUser();
+ }
+
+
/**
* @task internal
*/
Index: src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php
===================================================================
--- /dev/null
+++ src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Pushes a repository to its mirrors.
+ */
+final class PhabricatorRepositoryMirrorEngine
+ extends PhabricatorRepositoryEngine {
+
+ public function pushToMirrors() {
+ $repository = $this->getRepository();
+
+ if (!$repository->canMirror()) {
+ return;
+ }
+
+ $mirrors = id(new PhabricatorRepositoryMirrorQuery())
+ ->setViewer($this->getViewer())
+ ->withRepositoryPHIDs(array($repository->getPHID()))
+ ->execute();
+
+ // TODO: This is a little bit janky, but we don't have first-class
+ // infrastructure for running remote commands against an arbitrary remote
+ // right now. Just make an emphemeral copy of the repository and muck with
+ // it a little bit. In the medium term, we should pull this command stuff
+ // out and use it here and for "Land to ...".
+
+ $proxy = clone $repository;
+ $proxy->makeEphemeral();
+
+ $proxy->setDetail('hosting-enabled', false);
+ foreach ($mirrors as $mirror) {
+ $proxy->setDetail('remote-uri', $mirror->getRemoteURI());
+ $proxy->setCredentialPHID($mirror->getCredentialPHID());
+
+ $this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI()));
+
+ if (!$proxy->isGit()) {
+ throw new Exception('Unsupported VCS!');
+ }
+
+ $future = $proxy->getRemoteCommandFuture(
+ 'push --verbose --mirror -- %P',
+ $proxy->getRemoteURIEnvelope());
+
+ $future
+ ->setCWD($proxy->getLocalPath())
+ ->resolvex();
+ }
+ }
+
+}
Index: src/applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php
===================================================================
--- /dev/null
+++ src/applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php
@@ -0,0 +1,52 @@
+<?php
+
+final class PhabricatorRepositoryManagementMirrorWorkflow
+ extends PhabricatorRepositoryManagementWorkflow {
+
+ public function didConstruct() {
+ $this
+ ->setName('mirror')
+ ->setExamples('**mirror** [__options__] __repository__ ...')
+ ->setSynopsis(
+ pht('Push __repository__, named by callsign, to mirrors.'))
+ ->setArguments(
+ array(
+ array(
+ 'name' => 'verbose',
+ 'help' => pht('Show additional debugging information.'),
+ ),
+ array(
+ 'name' => 'repos',
+ 'wildcard' => true,
+ ),
+ ));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $repos = $this->loadRepositories($args, 'repos');
+
+ if (!$repos) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ "Specify one or more repositories to push to mirrors, by ".
+ "callsign."));
+ }
+
+ $console = PhutilConsole::getConsole();
+ foreach ($repos as $repo) {
+ $console->writeOut(
+ "%s\n",
+ pht('Pushing "%s" to mirrors...', $repo->getCallsign()));
+
+ $engine = id(new PhabricatorRepositoryMirrorEngine())
+ ->setRepository($repo)
+ ->setVerbose($args->getArg('verbose'))
+ ->pushToMirrors();
+ }
+
+ $console->writeOut("Done.\n");
+
+ return 0;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 18, 10:12 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6728956
Default Alt Text
D8066.id.diff (10 KB)

Event Timeline