1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Add an "--all" flag to "bin/differential migrate-hunk"

Summary:
Depends on D19369. Ref T13120. Add a flag to migrate every hunk.

This isn't terribly useful on its own, but I'm going to add an `--auto` flag next so that you can run `--auto --all` to migrate hunks to the preferred hunk format.

Test Plan: Ran `bin/differential migrate-hunk --all --to text`.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13120

Differential Revision: https://secure.phabricator.com/D19370
This commit is contained in:
epriestley 2018-04-13 13:15:46 -07:00
parent 6d1e007076
commit e3de7d09c0

View file

@ -6,7 +6,9 @@ final class PhabricatorDifferentialMigrateHunkWorkflow
protected function didConstruct() { protected function didConstruct() {
$this $this
->setName('migrate-hunk') ->setName('migrate-hunk')
->setExamples('**migrate-hunk** --id __hunk__ --to __storage__') ->setExamples(
"**migrate-hunk** --id __hunk__ --to __storage__\n".
"**migrate-hunk** --all")
->setSynopsis(pht('Migrate storage engines for a hunk.')) ->setSynopsis(pht('Migrate storage engines for a hunk.'))
->setArguments( ->setArguments(
array( array(
@ -20,14 +22,27 @@ final class PhabricatorDifferentialMigrateHunkWorkflow
'param' => 'storage', 'param' => 'storage',
'help' => pht('Storage engine to migrate to.'), 'help' => pht('Storage engine to migrate to.'),
), ),
array(
'name' => 'all',
'help' => pht('Migrate all hunks.'),
),
)); ));
} }
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
$id = $args->getArg('id'); $id = $args->getArg('id');
if (!$id) { $is_all = $args->getArg('all');
if ($is_all && $id) {
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht('Specify a hunk to migrate with --id.')); pht(
'Options "--all" (to migrate all hunks) and "--id" (to migrate a '.
'specific hunk) are mutually exclusive.'));
} else if (!$is_all && !$id) {
throw new PhutilArgumentUsageException(
pht(
'Specify a hunk to migrate with "--id", or migrate all hunks '.
'with "--all".'));
} }
$storage = $args->getArg('to'); $storage = $args->getArg('to');
@ -40,31 +55,30 @@ final class PhabricatorDifferentialMigrateHunkWorkflow
pht('Specify a hunk storage engine with --to.')); pht('Specify a hunk storage engine with --to.'));
} }
if ($id) {
$hunk = $this->loadHunk($id); $hunk = $this->loadHunk($id);
$old_data = $hunk->getChanges(); $hunks = array($hunk);
} else {
switch ($storage) { $hunks = new LiskMigrationIterator(new DifferentialHunk());
case DifferentialHunk::DATATYPE_TEXT:
$hunk->saveAsText();
$this->logOkay(
pht('TEXT'),
pht('Converted hunk to text storage.'));
break;
case DifferentialHunk::DATATYPE_FILE:
$hunk->saveAsFile();
$this->logOkay(
pht('FILE'),
pht('Converted hunk to file storage.'));
break;
} }
$hunk = $this->loadHunk($id); foreach ($hunks as $hunk) {
$new_data = $hunk->getChanges(); try {
$this->migrateHunk($hunk, $storage);
} catch (Exception $ex) {
// If we're migrating a single hunk, just throw the exception. If
// we're migrating multiple hunks, warn but continue.
if ($id) {
throw $ex;
}
if ($old_data !== $new_data) { $this->logWarn(
throw new Exception( pht('WARN'),
pht( pht(
'Integrity check failed: new file data differs fom old data!')); 'Failed to migrate hunk %d: %s',
$hunk->getID(),
$ex->getMessage()));
}
} }
return 0; return 0;
@ -82,5 +96,33 @@ final class PhabricatorDifferentialMigrateHunkWorkflow
return $hunk; return $hunk;
} }
private function migrateHunk(DifferentialHunk $hunk, $format) {
$old_data = $hunk->getChanges();
switch ($format) {
case DifferentialHunk::DATATYPE_TEXT:
$hunk->saveAsText();
$this->logOkay(
pht('TEXT'),
pht('Converted hunk to text storage.'));
break;
case DifferentialHunk::DATATYPE_FILE:
$hunk->saveAsFile();
$this->logOkay(
pht('FILE'),
pht('Converted hunk to file storage.'));
break;
}
$hunk = $this->loadHunk($hunk->getID());
$new_data = $hunk->getChanges();
if ($old_data !== $new_data) {
throw new Exception(
pht(
'Integrity check failed: new file data differs fom old data!'));
}
}
} }