Differential D14734 Diff 35634 src/applications/differential/controller/DifferentialRevisionOperationController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialRevisionOperationController.php
Show All 24 Lines | if ($barrier) { | ||||
->setTitle($barrier['title']) | ->setTitle($barrier['title']) | ||||
->appendParagraph($barrier['body']) | ->appendParagraph($barrier['body']) | ||||
->addCancelButton($detail_uri); | ->addCancelButton($detail_uri); | ||||
} | } | ||||
$diff = $revision->getActiveDiff(); | $diff = $revision->getActiveDiff(); | ||||
$repository = $revision->getRepository(); | $repository = $revision->getRepository(); | ||||
$ref_types = array( | $default_ref = $this->loadDefaultRef($repository); | ||||
PhabricatorRepositoryRefCursor::TYPE_BRANCH, | |||||
); | if ($default_ref) { | ||||
$v_ref = array($default_ref->getPHID()); | |||||
} else { | |||||
$v_ref = array(); | |||||
} | |||||
$e_ref = true; | $e_ref = true; | ||||
$errors = array(); | $errors = array(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$ref_phid = head($request->getArr('refPHIDs')); | $v_ref = $request->getArr('refPHIDs'); | ||||
$ref_phid = head($v_ref); | |||||
if (!strlen($ref_phid)) { | if (!strlen($ref_phid)) { | ||||
$e_ref = pht('Required'); | $e_ref = pht('Required'); | ||||
$errors[] = pht( | $errors[] = pht( | ||||
'You must select a branch to land this revision onto.'); | 'You must select a branch to land this revision onto.'); | ||||
} else { | } else { | ||||
$ref = id(new PhabricatorRepositoryRefCursorQuery()) | $ref = $this->newRefQuery($repository) | ||||
->setViewer($viewer) | |||||
->withPHIDs(array($ref_phid)) | ->withPHIDs(array($ref_phid)) | ||||
->withRepositoryPHIDs(array($repository->getPHID())) | |||||
->withRefTypes($ref_types) | |||||
->executeOne(); | ->executeOne(); | ||||
if (!$ref) { | if (!$ref) { | ||||
$e_ref = pht('Invalid'); | $e_ref = pht('Invalid'); | ||||
$errors[] = pht( | $errors[] = pht( | ||||
'You must select a branch from this repository to land this '. | 'You must select a branch from this repository to land this '. | ||||
'revision onto.'); | 'revision onto.'); | ||||
} | } | ||||
} | } | ||||
Show All 19 Lines | if ($request->isFormPost()) { | ||||
->setURI($detail_uri); | ->setURI($detail_uri); | ||||
} | } | ||||
} | } | ||||
$ref_datasource = id(new DiffusionRefDatasource()) | $ref_datasource = id(new DiffusionRefDatasource()) | ||||
->setParameters( | ->setParameters( | ||||
array( | array( | ||||
'repositoryPHIDs' => array($repository->getPHID()), | 'repositoryPHIDs' => array($repository->getPHID()), | ||||
'refTypes' => $ref_types, | 'refTypes' => $this->getTargetableRefTypes(), | ||||
)); | )); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
pht( | pht( | ||||
'In theory, this will do approximately what `arc land` would do. '. | 'In theory, this will do approximately what `arc land` would do. '. | ||||
'In practice, you will have a riveting adventure instead.')) | 'In practice, you will have a riveting adventure instead.')) | ||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setLabel(pht('Onto Branch')) | ->setLabel(pht('Onto Branch')) | ||||
->setName('refPHIDs') | ->setName('refPHIDs') | ||||
->setLimit(1) | ->setLimit(1) | ||||
->setError($e_ref) | ->setError($e_ref) | ||||
->setValue($v_ref) | |||||
->setDatasource($ref_datasource)) | ->setDatasource($ref_datasource)) | ||||
->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
pht( | pht( | ||||
'(WARNING) THIS FEATURE IS EXPERIMENTAL AND DANGEROUS! USE IT AT '. | '(WARNING) THIS FEATURE IS EXPERIMENTAL AND DANGEROUS! USE IT AT '. | ||||
'YOUR OWN RISK!')); | 'YOUR OWN RISK!')); | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->setTitle(pht('Land Revision')) | ->setTitle(pht('Land Revision')) | ||||
->setErrors($errors) | ->setErrors($errors) | ||||
->appendForm($form) | ->appendForm($form) | ||||
->addCancelButton($detail_uri) | ->addCancelButton($detail_uri) | ||||
->addSubmitButton(pht('Mutate Repository Unpredictably')); | ->addSubmitButton(pht('Mutate Repository Unpredictably')); | ||||
} | } | ||||
private function newRefQuery(PhabricatorRepository $repository) { | |||||
$viewer = $this->getViewer(); | |||||
return id(new PhabricatorRepositoryRefCursorQuery()) | |||||
->setViewer($viewer) | |||||
->withRepositoryPHIDs(array($repository->getPHID())) | |||||
->withRefTypes($this->getTargetableRefTypes()); | |||||
} | |||||
private function getTargetableRefTypes() { | |||||
return array( | |||||
PhabricatorRepositoryRefCursor::TYPE_BRANCH, | |||||
); | |||||
} | |||||
private function loadDefaultRef(PhabricatorRepository $repository) { | |||||
$default_name = $this->getDefaultRefName($repository); | |||||
if (!strlen($default_name)) { | |||||
return null; | |||||
} | |||||
return $this->newRefQuery($repository) | |||||
->withRefNames(array($default_name)) | |||||
->executeOne(); | |||||
} | |||||
private function getDefaultRefName(PhabricatorRepository $repository) { | |||||
return $repository->getDefaultBranch(); | |||||
} | |||||
} | } |