Differential D15747 Diff 37949 src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/ssh/DiffusionGitReceivePackSSHWorkflow.php
Show All 15 Lines | final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow { | ||||
protected function executeRepositoryOperations() { | protected function executeRepositoryOperations() { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
// This is a write, and must have write access. | // This is a write, and must have write access. | ||||
$this->requireWriteAccess(); | $this->requireWriteAccess(); | ||||
if ($this->shouldProxy()) { | if ($this->shouldProxy()) { | ||||
$command = $this->getProxyCommand(); | $command = $this->getProxyCommand(); | ||||
$is_proxy = true; | $did_synchronize = false; | ||||
} else { | } else { | ||||
$command = csprintf('git-receive-pack %s', $repository->getLocalPath()); | $command = csprintf('git-receive-pack %s', $repository->getLocalPath()); | ||||
$is_proxy = false; | |||||
$did_synchronize = true; | |||||
$repository->synchronizeWorkingCopyBeforeWrite(); | $repository->synchronizeWorkingCopyBeforeWrite(); | ||||
} | } | ||||
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command); | |||||
$future = id(new ExecFuture('%C', $command)) | $caught = null; | ||||
->setEnv($this->getEnvironment()); | try { | ||||
$err = $this->executeRepositoryCommand($command); | |||||
} catch (Exception $ex) { | |||||
$caught = $ex; | |||||
} | |||||
$err = $this->newPassthruCommand() | // We've committed the write (or rejected it), so we can release the lock | ||||
->setIOChannel($this->getIOChannel()) | // without waiting for the client to receive the acknowledgement. | ||||
->setCommandChannelFromExecFuture($future) | if ($did_synchronize) { | ||||
->execute(); | $repository->synchronizeWorkingCopyAfterWrite(); | ||||
} | |||||
if ($caught) { | |||||
throw $caught; | |||||
} | |||||
if (!$err) { | if (!$err) { | ||||
$repository->writeStatusMessage( | $repository->writeStatusMessage( | ||||
PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, | PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, | ||||
PhabricatorRepositoryStatusMessage::CODE_OKAY); | PhabricatorRepositoryStatusMessage::CODE_OKAY); | ||||
$this->waitForGitClient(); | $this->waitForGitClient(); | ||||
} | } | ||||
if (!$is_proxy) { | return $err; | ||||
$repository->synchronizeWorkingCopyAfterWrite(); | |||||
} | } | ||||
return $err; | private function executeRepositoryCommand($command) { | ||||
$repository = $this->getRepository(); | |||||
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command); | |||||
$future = id(new ExecFuture('%C', $command)) | |||||
->setEnv($this->getEnvironment()); | |||||
return $this->newPassthruCommand() | |||||
->setIOChannel($this->getIOChannel()) | |||||
->setCommandChannelFromExecFuture($future) | |||||
->execute(); | |||||
} | } | ||||
} | } |