Path: blob/master/src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php
12242 views
<?php12final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow {34protected function didConstruct() {5$this->setName('git-receive-pack');6$this->setArguments(7array(8array(9'name' => 'dir',10'wildcard' => true,11),12));13}1415protected function executeRepositoryOperations() {16// This is a write, and must have write access.17$this->requireWriteAccess();1819$is_proxy = $this->shouldProxy();20if ($is_proxy) {21return $this->executeRepositoryProxyOperations($for_write = true);22}2324$host_wait_start = microtime(true);2526$repository = $this->getRepository();27$viewer = $this->getSSHUser();28$device = AlmanacKeys::getLiveDevice();2930$cluster_engine = id(new DiffusionRepositoryClusterEngine())31->setViewer($viewer)32->setRepository($repository)33->setLog($this);3435$command = csprintf('git-receive-pack %s', $repository->getLocalPath());36$cluster_engine->synchronizeWorkingCopyBeforeWrite();3738if ($device) {39$this->writeClusterEngineLogMessage(40pht(41"# Ready to receive on cluster host \"%s\".\n",42$device->getName()));43}4445$log = $this->newProtocolLog($is_proxy);46if ($log) {47$this->setProtocolLog($log);48$log->didStartSession($command);49}5051$caught = null;52try {53$err = $this->executeRepositoryCommand($command);54} catch (Exception $ex) {55$caught = $ex;56}5758if ($log) {59$log->didEndSession();60}6162// We've committed the write (or rejected it), so we can release the lock63// without waiting for the client to receive the acknowledgement.64$cluster_engine->synchronizeWorkingCopyAfterWrite();6566if ($caught) {67throw $caught;68}6970if (!$err) {71$this->waitForGitClient();7273// When a repository is clustered, we reach this cleanup code on both74// the proxy and the actual final endpoint node. Don't do more cleanup75// or logging than we need to.76$repository->writeStatusMessage(77PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE,78PhabricatorRepositoryStatusMessage::CODE_OKAY);7980$host_wait_end = microtime(true);8182$this->updatePushLogWithTimingInformation(83$this->getClusterEngineLogProperty('writeWait'),84$this->getClusterEngineLogProperty('readWait'),85($host_wait_end - $host_wait_start));86}8788return $err;89}9091private function executeRepositoryCommand($command) {92$repository = $this->getRepository();93$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);9495$future = id(new ExecFuture('%C', $command))96->setEnv($this->getEnvironment());9798return $this->newPassthruCommand()99->setIOChannel($this->getIOChannel())100->setCommandChannelFromExecFuture($future)101->execute();102}103104private function updatePushLogWithTimingInformation(105$write_wait,106$read_wait,107$host_wait) {108109if ($write_wait !== null) {110$write_wait = (int)(1000000 * $write_wait);111}112113if ($read_wait !== null) {114$read_wait = (int)(1000000 * $read_wait);115}116117if ($host_wait !== null) {118$host_wait = (int)(1000000 * $host_wait);119}120121$identifier = $this->getRequestIdentifier();122123$event = new PhabricatorRepositoryPushEvent();124$conn = $event->establishConnection('w');125126queryfx(127$conn,128'UPDATE %T SET writeWait = %nd, readWait = %nd, hostWait = %nd129WHERE requestIdentifier = %s',130$event->getTableName(),131$write_wait,132$read_wait,133$host_wait,134$identifier);135}136137}138139140