mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
dc75b4bd06
Summary: Ref T10860. This doesn't change anything, it just separates all this stuff out of `PhabricatorRepository` since I'm planning to add a bit more state to it and it's already pretty big and fairly separable. Test Plan: Pulled, pushed, browsed Diffusion. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10860 Differential Revision: https://secure.phabricator.com/D15790
76 lines
2 KiB
PHP
76 lines
2 KiB
PHP
<?php
|
|
|
|
final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow {
|
|
|
|
protected function didConstruct() {
|
|
$this->setName('git-receive-pack');
|
|
$this->setArguments(
|
|
array(
|
|
array(
|
|
'name' => 'dir',
|
|
'wildcard' => true,
|
|
),
|
|
));
|
|
}
|
|
|
|
protected function executeRepositoryOperations() {
|
|
$repository = $this->getRepository();
|
|
$viewer = $this->getViewer();
|
|
|
|
// This is a write, and must have write access.
|
|
$this->requireWriteAccess();
|
|
|
|
$cluster_engine = id(new DiffusionRepositoryClusterEngine())
|
|
->setViewer($viewer)
|
|
->setRepository($repository);
|
|
|
|
if ($this->shouldProxy()) {
|
|
$command = $this->getProxyCommand();
|
|
$did_synchronize = false;
|
|
} else {
|
|
$command = csprintf('git-receive-pack %s', $repository->getLocalPath());
|
|
$did_synchronize = true;
|
|
$cluster_engine->synchronizeWorkingCopyBeforeWrite();
|
|
}
|
|
|
|
$caught = null;
|
|
try {
|
|
$err = $this->executeRepositoryCommand($command);
|
|
} catch (Exception $ex) {
|
|
$caught = $ex;
|
|
}
|
|
|
|
// We've committed the write (or rejected it), so we can release the lock
|
|
// without waiting for the client to receive the acknowledgement.
|
|
if ($did_synchronize) {
|
|
$cluster_engine->synchronizeWorkingCopyAfterWrite();
|
|
}
|
|
|
|
if ($caught) {
|
|
throw $caught;
|
|
}
|
|
|
|
if (!$err) {
|
|
$repository->writeStatusMessage(
|
|
PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE,
|
|
PhabricatorRepositoryStatusMessage::CODE_OKAY);
|
|
$this->waitForGitClient();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
}
|