Path: blob/master/src/applications/diffusion/ssh/DiffusionMercurialServeSSHWorkflow.php
12242 views
<?php12final class DiffusionMercurialServeSSHWorkflow3extends DiffusionMercurialSSHWorkflow {45protected $didSeeWrite;67protected function didConstruct() {8$this->setName('hg');9$this->setArguments(10array(11array(12'name' => 'repository',13'short' => 'R',14'param' => 'repo',15),16array(17'name' => 'stdio',18),19array(20'name' => 'command',21'wildcard' => true,22),23));24}2526protected function identifyRepository() {27$args = $this->getArgs();28$path = $args->getArg('repository');29return $this->loadRepositoryWithPath(30$path,31PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL);32}3334protected function executeRepositoryOperations() {35$repository = $this->getRepository();36$args = $this->getArgs();3738if (!$args->getArg('stdio')) {39throw new Exception(pht('Expected `%s`!', 'hg ... --stdio'));40}4142if ($args->getArg('command') !== array('serve')) {43throw new Exception(pht('Expected `%s`!', 'hg ... serve'));44}4546if ($this->shouldProxy()) {47// NOTE: For now, we're always requesting a writable node. The request48// may not actually need one, but we can't currently determine whether49// it is read-only or not at this phase of evaluation.50$command = $this->getProxyCommand(true);51} else {52$command = csprintf(53'hg -R %s serve --stdio',54$repository->getLocalPath());55}56$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);5758$future = id(new ExecFuture('%C', $command))59->setEnv($this->getEnvironment());6061$io_channel = $this->getIOChannel();62$protocol_channel = new DiffusionMercurialWireClientSSHProtocolChannel(63$io_channel);6465$err = id($this->newPassthruCommand())66->setIOChannel($protocol_channel)67->setCommandChannelFromExecFuture($future)68->setWillWriteCallback(array($this, 'willWriteMessageCallback'))69->execute();7071if (!$err && $this->didSeeWrite) {72$repository->writeStatusMessage(73PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE,74PhabricatorRepositoryStatusMessage::CODE_OKAY);75}7677return $err;78}7980public function willWriteMessageCallback(81PhabricatorSSHPassthruCommand $command,82$message) {8384$command = $message['command'];8586// Check if this is a readonly command.8788$is_readonly = false;89if ($command == 'batch') {90$cmds = idx($message['arguments'], 'cmds');91if (DiffusionMercurialWireProtocol::isReadOnlyBatchCommand($cmds)) {92$is_readonly = true;93}94} else if (DiffusionMercurialWireProtocol::isReadOnlyCommand($command)) {95$is_readonly = true;96}9798if (!$is_readonly) {99$this->requireWriteAccess();100$this->didSeeWrite = true;101}102103return $message['raw'];104}105106protected function raiseWrongVCSException(107PhabricatorRepository $repository) {108throw new Exception(109pht(110'This repository ("%s") is not a Mercurial repository. Use "%s" to '.111'interact with this repository.',112$repository->getDisplayName(),113$repository->getVersionControlSystem()));114}115116}117118119