mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Add possibility to upload a diff file instead of using copy-paste.
Test Plan: Go to /differential/diff/create and upload a diff file - result should be the same as pasting the diff into the textarea. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Differential Revision: 1019
This commit is contained in:
parent
dfa2e29a01
commit
a11053d0fa
3 changed files with 22 additions and 3 deletions
|
@ -24,7 +24,12 @@ class DifferentialDiffCreateController extends DifferentialController {
|
|||
|
||||
if ($request->isFormPost()) {
|
||||
$parser = new ArcanistDiffParser();
|
||||
$diff = $request->getStr('diff');
|
||||
$diff = null;
|
||||
try {
|
||||
$diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
|
||||
} catch (Exception $ex) {
|
||||
$diff = $request->getStr('diff');
|
||||
}
|
||||
$changes = $parser->parseDiff($diff);
|
||||
$diff = DifferentialDiff::newFromRawChanges($changes);
|
||||
|
||||
|
@ -42,17 +47,23 @@ class DifferentialDiffCreateController extends DifferentialController {
|
|||
$form = new AphrontFormView();
|
||||
$form
|
||||
->setAction('/differential/diff/create/')
|
||||
->setEncType('multipart/form-data')
|
||||
->setUser($request->getUser())
|
||||
->appendChild(
|
||||
'<p class="aphront-form-instructions">The best way to create a '.
|
||||
'Differential diff is by using <strong>Arcanist</strong>, but you '.
|
||||
'can also just paste a diff (e.g., from <tt>svn diff</tt> or '.
|
||||
'<tt>git diff</tt>) into this box if you really want.</p>')
|
||||
'<tt>git diff</tt>) into this box or upload it as a file if you '.
|
||||
'really want.</p>')
|
||||
->appendChild(
|
||||
id(new AphrontFormTextAreaControl())
|
||||
->setLabel('Raw Diff')
|
||||
->setName('diff')
|
||||
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
->setLabel('Raw Diff from file')
|
||||
->setName('diff-file'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue("Create Diff \xC2\xBB"));
|
||||
|
|
|
@ -12,7 +12,9 @@ phutil_require_module('phabricator', 'aphront/response/redirect');
|
|||
phutil_require_module('phabricator', 'applications/differential/constants/lintstatus');
|
||||
phutil_require_module('phabricator', 'applications/differential/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/diff');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/file');
|
||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||
phutil_require_module('phabricator', 'view/form/control/textarea');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
|
|
@ -41,7 +41,7 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
|||
PhabricatorPHIDConstants::PHID_TYPE_FILE);
|
||||
}
|
||||
|
||||
public static function newFromPHPUpload($spec, array $params = array()) {
|
||||
public static function readUploadedFileData($spec) {
|
||||
if (!$spec) {
|
||||
throw new Exception("No file was uploaded!");
|
||||
}
|
||||
|
@ -64,6 +64,12 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
|||
throw new Exception("File size disagrees with uploaded size.");
|
||||
}
|
||||
|
||||
return $file_data;
|
||||
}
|
||||
|
||||
public static function newFromPHPUpload($spec, array $params = array()) {
|
||||
$file_data = self::readUploadedFileData($spec);
|
||||
|
||||
$file_name = nonempty(
|
||||
idx($params, 'name'),
|
||||
idx($spec, 'name'));
|
||||
|
|
Loading…
Reference in a new issue