mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
Provide differential.getdiff, useful for 'arc patch'.
Summary: Test Plan: ran 'arc patch' Reviewers: CC:
This commit is contained in:
parent
0e7729c78f
commit
e691dca6c6
4 changed files with 133 additions and 0 deletions
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class ConduitAPI_differential_getdiff_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Load the content of a diff from Differential.";
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'revision_id' => '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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/diff');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/revision');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('ConduitAPI_differential_getdiff_Method.php');
|
|
@ -254,4 +254,5 @@ class ManiphestTaskDetailController extends ManiphestController {
|
|||
'title' => 'T'.$task->getID().' '.$task->getTitle(),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue