From e691dca6c681d3c24e0a0fa22650810cea4c4842 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 18 Feb 2011 22:15:28 -0800 Subject: [PATCH] Provide differential.getdiff, useful for 'arc patch'. Summary: Test Plan: ran 'arc patch' Reviewers: CC: --- src/__phutil_library_map__.php | 2 + ...ConduitAPI_differential_getdiff_Method.php | 113 ++++++++++++++++++ .../method/differential/getdiff/__init__.php | 17 +++ .../ManiphestTaskDetailController.php | 1 + 4 files changed, 133 insertions(+) create mode 100644 src/applications/conduit/method/differential/getdiff/ConduitAPI_differential_getdiff_Method.php create mode 100644 src/applications/conduit/method/differential/getdiff/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 31cc63253e..99e5e17146 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -68,6 +68,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_createrevision_Method' => 'applications/conduit/method/differential/createrevision', 'ConduitAPI_differential_find_Method' => 'applications/conduit/method/differential/find', 'ConduitAPI_differential_getcommitmessage_Method' => 'applications/conduit/method/differential/getcommitmessage', + 'ConduitAPI_differential_getdiff_Method' => 'applications/conduit/method/differential/getdiff', 'ConduitAPI_differential_markcommitted_Method' => 'applications/conduit/method/differential/markcommitted', 'ConduitAPI_differential_parsecommitmessage_Method' => 'applications/conduit/method/differential/parsecommitmessage', 'ConduitAPI_differential_setdiffproperty_Method' => 'applications/conduit/method/differential/setdiffproperty', @@ -330,6 +331,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_createrevision_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_find_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_getcommitmessage_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_getdiff_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_markcommitted_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/differential/getdiff/ConduitAPI_differential_getdiff_Method.php b/src/applications/conduit/method/differential/getdiff/ConduitAPI_differential_getdiff_Method.php new file mode 100644 index 0000000000..bb5e3f31ab --- /dev/null +++ b/src/applications/conduit/method/differential/getdiff/ConduitAPI_differential_getdiff_Method.php @@ -0,0 +1,113 @@ + 'optional id', + 'diff_id' => 'optional id', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR_BAD_REVISION' => 'No such revision exists.', + 'ERR_BAD_DIFF' => 'No such diff exists.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $diff = null; + + $revision_id = $request->getValue('revision_id'); + if ($revision_id) { + $revision = id(new DifferentialRevision())->load($revision_id); + if (!$revision) { + throw new ConduitException('ERR_BAD_REVISION'); + } + $diff = id(new DifferentialDiff())->loadOneWhere( + 'revisionID = %d ORDER BY id DESC LIMIT 1', + $revision->getID()); + } else { + $diff_id = $request->getValue('diff_id'); + if ($diff_id) { + $diff = id(new DifferentialDiff())->load($diff_id); + } + } + + if (!$diff) { + throw new ConduitException('ERR_BAD_DIFF'); + } + + $diff->attachChangesets($diff->loadChangesets()); + // TODO: We could batch this to improve performance. + foreach ($diff->getChangesets() as $changeset) { + $changeset->attachHunks($changeset->loadHunks()); + } + + $dict = array( + 'id' => $diff->getID(), + 'parent' => $diff->getParentRevisionID(), + 'sourceControlBaseRevision' => $diff->getSourceControlBaseRevision(), + 'sourceControlPath' => $diff->getSourceControlPath(), + 'changes' => array(), + ); + + foreach ($diff->getChangesets() as $changeset) { + $hunks = array(); + foreach ($changeset->getHunks() as $hunk) { + $hunks[] = array( + 'oldOffset' => $hunk->getOldOffset(), + 'newOffset' => $hunk->getNewOffset(), + 'oldLength' => $hunk->getOldLen(), + 'newLength' => $hunk->getNewLen(), + 'addLines' => null, + 'delLines' => null, + 'isMissingOldNewline' => null, + 'isMissingNewNewline' => null, + 'corpus' => $hunk->getChanges(), + ); + } + $change = array( + 'metadata' => $changeset->getMetadata(), + 'oldPath' => $changeset->getOldFile(), + 'currentPath' => $changeset->getFileName(), + 'awayPaths' => $changeset->getAwayPaths(), + 'oldProperties' => $changeset->getOldProperties(), + 'newProperties' => $changeset->getNewProperties(), + 'type' => $changeset->getChangeType(), + 'fileType' => $changeset->getFileType(), + 'commitHash' => null, + 'hunks' => $hunks, + ); + $dict['changes'][] = $change; + } + + return $dict; + } + +} diff --git a/src/applications/conduit/method/differential/getdiff/__init__.php b/src/applications/conduit/method/differential/getdiff/__init__.php new file mode 100644 index 0000000000..15399190d3 --- /dev/null +++ b/src/applications/conduit/method/differential/getdiff/__init__.php @@ -0,0 +1,17 @@ + 'T'.$task->getID().' '.$task->getTitle(), )); } + }