diff --git a/bin/hunks b/bin/hunks new file mode 120000 --- /dev/null +++ b/bin/hunks @@ -0,0 +1 @@ +../scripts/setup/manage_hunks.php \ No newline at end of file diff --git a/scripts/setup/manage_hunks.php b/scripts/setup/manage_hunks.php new file mode 100755 --- /dev/null +++ b/scripts/setup/manage_hunks.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +setTagline('manage hunks'); +$args->setSynopsis(<<parseStandardArguments(); + +$workflows = id(new PhutilSymbolLoader()) + ->setAncestorClass('PhabricatorHunksManagementWorkflow') + ->loadObjects(); +$workflows[] = new PhutilHelpArgumentWorkflow(); +$args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1665,6 +1665,8 @@ 'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php', 'PhabricatorHovercardExample' => 'applications/uiexample/examples/PhabricatorHovercardExample.php', 'PhabricatorHovercardView' => 'view/widget/hovercard/PhabricatorHovercardView.php', + 'PhabricatorHunksManagementMigrateWorkflow' => 'applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php', + 'PhabricatorHunksManagementWorkflow' => 'applications/differential/management/PhabricatorHunksManagementWorkflow.php', 'PhabricatorIRCBot' => 'infrastructure/daemon/bot/PhabricatorIRCBot.php', 'PhabricatorIRCProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php', 'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/bot/handler/PhabricatorIRCProtocolHandler.php', @@ -4488,6 +4490,8 @@ 'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController', 'PhabricatorHovercardExample' => 'PhabricatorUIExample', 'PhabricatorHovercardView' => 'AphrontView', + 'PhabricatorHunksManagementMigrateWorkflow' => 'PhabricatorHunksManagementWorkflow', + 'PhabricatorHunksManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorIRCBot' => 'PhabricatorDaemon', 'PhabricatorIRCProtocolAdapter' => 'PhabricatorBaseProtocolAdapter', 'PhabricatorIRCProtocolHandler' => 'PhabricatorBotHandler', diff --git a/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php b/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php new file mode 100644 --- /dev/null +++ b/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php @@ -0,0 +1,48 @@ +setName('migrate') + ->setExamples('**migrate**') + ->setSynopsis(pht('Migrate hunks to modern storage.')) + ->setArguments(array()); + } + + public function execute(PhutilArgumentParser $args) { + $saw_any_rows = false; + $console = PhutilConsole::getConsole(); + + $table = new DifferentialHunkLegacy(); + foreach (new LiskMigrationIterator($table) as $hunk) { + $saw_any_rows = true; + + $id = $hunk->getID(); + $console->writeOut("%s\n", pht('Migrating hunk %d...', $id)); + + $new_hunk = id(new DifferentialHunkModern()) + ->setChangesetID($hunk->getChangesetID()) + ->setOldOffset($hunk->getOldOffset()) + ->setOldLen($hunk->getOldLen()) + ->setNewOffset($hunk->getNewOffset()) + ->setNewLen($hunk->getNewLen()) + ->setChanges($hunk->getChanges()) + ->setDateCreated($hunk->getDateCreated()) + ->setDateModified($hunk->getDateModified()); + + $hunk->openTransaction(); + $new_hunk->save(); + $hunk->delete(); + $hunk->saveTransaction(); + } + + if ($saw_any_rows) { + $console->writeOut("%s\n", pht('Done.')); + } else { + $console->writeOut("%s\n", pht('No rows to migrate.')); + } + } + +} diff --git a/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php b/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php new file mode 100644 --- /dev/null +++ b/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php @@ -0,0 +1,6 @@ +changes); + $lines = explode("\n", $this->getChanges()); // NOTE: To determine whether the recomposed file should have a trailing // newline, we look for a "\ No newline at end of file" line which appears