From a4e2eb3d8c6cdd8bb915f941201ef2a6522a2a1d Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 20 Jun 2012 12:35:04 -0700 Subject: [PATCH] Add a "differential.createrawdiff" Conduit method Summary: "differential.creatediff" requires a mostly-parsed diff, but there's no reason we can't make DifferentialDiffs out of raw diffs. This mainly serves to lower the adoption barrier if getting "arc" distributed is too much of a hassle. Test Plan: Made a diff out of a raw block of diff text. Reviewers: ffx, vrana, btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D2751 --- src/__phutil_library_map__.php | 4 ++ .../ConduitAPI_differential_Method.php | 35 +++++++++++ ...tAPI_differential_createrawdiff_Method.php | 61 +++++++++++++++++++ .../DifferentialDiffCreateController.php | 20 +++--- 4 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 src/applications/conduit/method/differential/ConduitAPI_differential_Method.php create mode 100644 src/applications/conduit/method/differential/ConduitAPI_differential_createrawdiff_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 27c4c2ac0e..68a3557541 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -130,9 +130,11 @@ phutil_register_library_map(array( 'ConduitAPI_conduit_ping_Method' => 'applications/conduit/method/conduit/ConduitAPI_conduit_ping_Method.php', 'ConduitAPI_daemon_launched_Method' => 'applications/conduit/method/daemon/ConduitAPI_daemon_launched_Method.php', 'ConduitAPI_daemon_log_Method' => 'applications/conduit/method/daemon/ConduitAPI_daemon_log_Method.php', + 'ConduitAPI_differential_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_Method.php', 'ConduitAPI_differential_close_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_close_Method.php', 'ConduitAPI_differential_createcomment_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createcomment_Method.php', 'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_creatediff_Method.php', + 'ConduitAPI_differential_createrawdiff_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createrawdiff_Method.php', 'ConduitAPI_differential_createrevision_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_createrevision_Method.php', 'ConduitAPI_differential_find_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_find_Method.php', 'ConduitAPI_differential_getalldiffs_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_getalldiffs_Method.php', @@ -1195,9 +1197,11 @@ phutil_register_library_map(array( 'ConduitAPI_conduit_ping_Method' => 'ConduitAPIMethod', 'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod', 'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_close_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_createcomment_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_createrawdiff_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_createrevision_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_find_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_getalldiffs_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/differential/ConduitAPI_differential_Method.php b/src/applications/conduit/method/differential/ConduitAPI_differential_Method.php new file mode 100644 index 0000000000..32d78cf88e --- /dev/null +++ b/src/applications/conduit/method/differential/ConduitAPI_differential_Method.php @@ -0,0 +1,35 @@ +getID().'/'; + $uri = PhabricatorEnv::getProductionURI($uri); + + return array( + 'id' => $diff->getID(), + 'uri' => $uri, + ); + } + + +} diff --git a/src/applications/conduit/method/differential/ConduitAPI_differential_createrawdiff_Method.php b/src/applications/conduit/method/differential/ConduitAPI_differential_createrawdiff_Method.php new file mode 100644 index 0000000000..5c98142216 --- /dev/null +++ b/src/applications/conduit/method/differential/ConduitAPI_differential_createrawdiff_Method.php @@ -0,0 +1,61 @@ + 'required string', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $raw_diff = $request->getValue('diff'); + + $parser = new ArcanistDiffParser(); + $changes = $parser->parseDiff($raw_diff); + $diff = DifferentialDiff::newFromRawChanges($changes); + + $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); + $diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP); + + $diff->setAuthorPHID($request->getUser()->getPHID()); + $diff->setCreationMethod('web'); + $diff->save(); + + return $this->buildDiffInfoDictionary($diff); + } + +} diff --git a/src/applications/differential/controller/DifferentialDiffCreateController.php b/src/applications/differential/controller/DifferentialDiffCreateController.php index b3b91298c4..b568145e49 100644 --- a/src/applications/differential/controller/DifferentialDiffCreateController.php +++ b/src/applications/differential/controller/DifferentialDiffCreateController.php @@ -23,25 +23,23 @@ final class DifferentialDiffCreateController extends DifferentialController { $request = $this->getRequest(); if ($request->isFormPost()) { - $parser = new ArcanistDiffParser(); $diff = null; try { $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']); } catch (Exception $ex) { $diff = $request->getStr('diff'); } - $changes = $parser->parseDiff($diff); - $diff = DifferentialDiff::newFromRawChanges($changes); - $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); - $diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP); + $call = new ConduitCall( + 'differential.createrawdiff', + array( + 'diff' => $diff, + )); + $call->setUser($request->getUser()); + $result = $call->execute(); - $diff->setAuthorPHID($request->getUser()->getPHID()); - $diff->setCreationMethod('web'); - $diff->save(); - - return id(new AphrontRedirectResponse()) - ->setURI('/differential/diff/'.$diff->getID().'/'); + $path = id(new PhutilURI($result['uri']))->getPath(); + return id(new AphrontRedirectResponse())->setURI($path); } $form = new AphrontFormView();