diff --git a/resources/sql/autopatches/20150609.diffhunk.1.sql b/resources/sql/autopatches/20150609.diffhunk.1.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20150609.diffhunk.1.sql @@ -0,0 +1,5 @@ +RENAME TABLE {$NAMESPACE}_differential.differential_hunk + TO {$NAMESPACE}_differential.differential_hunk_legacy; + +RENAME TABLE {$NAMESPACE}_differential.differential_hunk_modern + TO {$NAMESPACE}_differential.differential_hunk; diff --git a/resources/sql/autopatches/20150609.diffhunk.2.php b/resources/sql/autopatches/20150609.diffhunk.2.php new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20150609.diffhunk.2.php @@ -0,0 +1,29 @@ +establishConnection('w'); +$legacy_table = 'differential_hunk_legacy'; + +foreach (new LiskRawMigrationIterator($conn_w, $legacy_table) as $legacy_hunk) { + $id = $legacy_hunk['id']; + + echo pht('Migrating hunk %d...', $id)."\n"; + + $modern_hunk = id(new DifferentialHunk()) + ->setChangesetID($legacy_hunk['changesetID']) + ->setOldOffset($legacy_hunk['oldOffset']) + ->setOldLen($legacy_hunk['oldLen']) + ->setNewOffset($legacy_hunk['newOffset']) + ->setNewLen($legacy_hunk['newLen']) + ->setChanges($legacy_hunk['changes']) + ->setDateCreated($legacy_hunk['dateCreated']) + ->setDateModified($legacy_hunk['dateModified']); + + $modern_hunk->openTransaction(); + queryfx( + $conn_w, + 'DELETE FROM %T WHERE id = %d', + $legacy_table, + $id); + $modern_hunk->save(); + $modern_hunk->saveTransaction(); +} diff --git a/resources/sql/autopatches/20150609.diffhunk.3.sql b/resources/sql/autopatches/20150609.diffhunk.3.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20150609.diffhunk.3.sql @@ -0,0 +1 @@ +DROP TABLE {$NAMESPACE}_differential.differential_hunk_legacy; 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 @@ -388,13 +388,11 @@ 'DifferentialJIRAIssuesField' => 'applications/differential/customfield/DifferentialJIRAIssuesField.php', 'DifferentialLandingActionMenuEventListener' => 'applications/differential/landing/DifferentialLandingActionMenuEventListener.php', 'DifferentialLandingStrategy' => 'applications/differential/landing/DifferentialLandingStrategy.php', - 'DifferentialLegacyHunk' => 'applications/differential/storage/DifferentialLegacyHunk.php', 'DifferentialLineAdjustmentMap' => 'applications/differential/parser/DifferentialLineAdjustmentMap.php', 'DifferentialLintField' => 'applications/differential/customfield/DifferentialLintField.php', 'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php', 'DifferentialLocalCommitsView' => 'applications/differential/view/DifferentialLocalCommitsView.php', 'DifferentialManiphestTasksField' => 'applications/differential/customfield/DifferentialManiphestTasksField.php', - 'DifferentialModernHunk' => 'applications/differential/storage/DifferentialModernHunk.php', 'DifferentialParseCacheGarbageCollector' => 'applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php', 'DifferentialParseCommitMessageConduitAPIMethod' => 'applications/differential/conduit/DifferentialParseCommitMessageConduitAPIMethod.php', 'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php', @@ -1947,8 +1945,6 @@ 'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php', 'PhabricatorHovercardUIExample' => 'applications/uiexample/examples/PhabricatorHovercardUIExample.php', 'PhabricatorHovercardView' => 'view/widget/hovercard/PhabricatorHovercardView.php', - 'PhabricatorHunksManagementMigrateWorkflow' => 'applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php', - 'PhabricatorHunksManagementWorkflow' => 'applications/differential/management/PhabricatorHunksManagementWorkflow.php', 'PhabricatorIRCProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php', 'PhabricatorIconRemarkupRule' => 'applications/macro/markup/PhabricatorIconRemarkupRule.php', 'PhabricatorImageMacroRemarkupRule' => 'applications/macro/markup/PhabricatorImageMacroRemarkupRule.php', @@ -3666,12 +3662,10 @@ 'DifferentialInlineCommentQuery' => 'PhabricatorOffsetPagedQuery', 'DifferentialJIRAIssuesField' => 'DifferentialStoredCustomField', 'DifferentialLandingActionMenuEventListener' => 'PhabricatorEventListener', - 'DifferentialLegacyHunk' => 'DifferentialHunk', 'DifferentialLineAdjustmentMap' => 'Phobject', 'DifferentialLintField' => 'DifferentialCustomField', 'DifferentialLocalCommitsView' => 'AphrontView', 'DifferentialManiphestTasksField' => 'DifferentialCoreCustomField', - 'DifferentialModernHunk' => 'DifferentialHunk', 'DifferentialParseCacheGarbageCollector' => 'PhabricatorGarbageCollector', 'DifferentialParseCommitMessageConduitAPIMethod' => 'DifferentialConduitAPIMethod', 'DifferentialParseRenderTestCase' => 'PhabricatorTestCase', @@ -5397,8 +5391,6 @@ 'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController', 'PhabricatorHovercardUIExample' => 'PhabricatorUIExample', 'PhabricatorHovercardView' => 'AphrontView', - 'PhabricatorHunksManagementMigrateWorkflow' => 'PhabricatorHunksManagementWorkflow', - 'PhabricatorHunksManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorIRCProtocolAdapter' => 'PhabricatorProtocolAdapter', 'PhabricatorIconRemarkupRule' => 'PhutilRemarkupRule', 'PhabricatorImageMacroRemarkupRule' => 'PhutilRemarkupRule', diff --git a/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php b/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php deleted file mode 100644 --- a/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php +++ /dev/null @@ -1,62 +0,0 @@ -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 DifferentialLegacyHunk(); - 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 DifferentialModernHunk()) - ->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(); - - $old_len = strlen($hunk->getChanges()); - $new_len = strlen($new_hunk->getData()); - if ($old_len) { - $diff_len = ($old_len - $new_len); - $console->writeOut( - "%s\n", - pht( - 'Saved %s bytes (%s).', - new PhutilNumber($diff_len), - sprintf('%.1f%%', 100 * ($diff_len / $old_len)))); - } - - break; - } - - 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 deleted file mode 100644 --- a/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php +++ /dev/null @@ -1,4 +0,0 @@ -setChanges("+a\n b\n-c"); $hunk->setNewOffset(1); $hunk->setNewLen(2); @@ -20,7 +20,7 @@ ); foreach ($tests as $changes => $expected) { - $hunk = new DifferentialModernHunk(); + $hunk = new DifferentialHunk(); $hunk->setChanges($changes); $hunk->setNewOffset(11); $hunk->setNewLen(3); diff --git a/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php b/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php --- a/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php +++ b/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php @@ -14,7 +14,7 @@ $new_len, $changes) { - $hunk = id(new DifferentialModernHunk()) + $hunk = id(new DifferentialHunk()) ->setOldOffset($old_offset) ->setOldLen($old_len) ->setNewOffset($new_offset) diff --git a/src/applications/differential/query/DifferentialHunkQuery.php b/src/applications/differential/query/DifferentialHunkQuery.php --- a/src/applications/differential/query/DifferentialHunkQuery.php +++ b/src/applications/differential/query/DifferentialHunkQuery.php @@ -31,38 +31,17 @@ } protected function loadPage() { - $all_results = array(); - - // Load modern hunks. - $table = new DifferentialModernHunk(); - $conn_r = $table->establishConnection('r'); - - $modern_data = queryfx_all( - $conn_r, - 'SELECT * FROM %T %Q %Q %Q', - $table->getTableName(), - $this->buildWhereClause($conn_r), - $this->buildOrderClause($conn_r), - $this->buildLimitClause($conn_r)); - $modern_results = $table->loadAllFromArray($modern_data); - - - // Now, load legacy hunks. - $table = new DifferentialLegacyHunk(); + $table = new DifferentialHunk(); $conn_r = $table->establishConnection('r'); - $legacy_data = queryfx_all( + $data = queryfx_all( $conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); - $legacy_results = $table->loadAllFromArray($legacy_data); - - // Strip all the IDs off since they're not unique and nothing should be - // using them. - return array_values(array_merge($legacy_results, $modern_results)); + return $table->loadAllFromArray($data); } protected function willFilterPage(array $hunks) { diff --git a/src/applications/differential/storage/DifferentialChangeset.php b/src/applications/differential/storage/DifferentialChangeset.php --- a/src/applications/differential/storage/DifferentialChangeset.php +++ b/src/applications/differential/storage/DifferentialChangeset.php @@ -98,18 +98,11 @@ public function delete() { $this->openTransaction(); - $legacy_hunks = id(new DifferentialLegacyHunk())->loadAllWhere( + $hunks = id(new DifferentialHunk())->loadAllWhere( 'changesetID = %d', $this->getID()); - foreach ($legacy_hunks as $legacy_hunk) { - $legacy_hunk->delete(); - } - - $modern_hunks = id(new DifferentialModernHunk())->loadAllWhere( - 'changesetID = %d', - $this->getID()); - foreach ($modern_hunks as $modern_hunk) { - $modern_hunk->delete(); + foreach ($hunks as $hunk) { + $hunk->delete(); } $this->unsavedHunks = array(); diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -173,7 +173,7 @@ $hunks = $change->getHunks(); if ($hunks) { foreach ($hunks as $hunk) { - $dhunk = new DifferentialModernHunk(); + $dhunk = new DifferentialHunk(); $dhunk->setOldOffset($hunk->getOldOffset()); $dhunk->setOldLen($hunk->getOldLength()); $dhunk->setNewOffset($hunk->getNewOffset()); diff --git a/src/applications/differential/storage/DifferentialHunk.php b/src/applications/differential/storage/DifferentialHunk.php --- a/src/applications/differential/storage/DifferentialHunk.php +++ b/src/applications/differential/storage/DifferentialHunk.php @@ -1,8 +1,18 @@ array( + 'data' => true, + ), + self::CONFIG_COLUMN_SCHEMA => array( + 'dataType' => 'bytes4', + 'dataEncoding' => 'text16?', + 'dataFormat' => 'bytes4', + 'oldOffset' => 'uint32', + 'oldLen' => 'uint32', + 'newOffset' => 'uint32', + 'newLen' => 'uint32', + ), + self::CONFIG_KEY_SCHEMA => array( + 'key_changeset' => array( + 'columns' => array('changesetID'), + ), + 'key_created' => array( + 'columns' => array('dateCreated'), + ), + ), + ) + parent::getConfiguration(); + } public function getAddedLines() { return $this->makeContent($include = '+'); @@ -210,6 +249,83 @@ return $this; } + public function setChanges($text) { + $this->rawData = $text; + + $this->dataEncoding = $this->detectEncodingForStorage($text); + $this->dataType = self::DATATYPE_TEXT; + $this->dataFormat = self::DATAFORMAT_RAW; + $this->data = $text; + + return $this; + } + + public function getChanges() { + return $this->getUTF8StringFromStorage( + $this->getRawData(), + nonempty($this->forcedEncoding, $this->getDataEncoding())); + } + + public function forceEncoding($encoding) { + $this->forcedEncoding = $encoding; + return $this; + } + + public function save() { + $type = $this->getDataType(); + $format = $this->getDataFormat(); + + // Before saving the data, attempt to compress it. + if ($type == self::DATATYPE_TEXT) { + if ($format == self::DATAFORMAT_RAW) { + $data = $this->getData(); + $deflated = PhabricatorCaches::maybeDeflateData($data); + if ($deflated !== null) { + $this->data = $deflated; + $this->dataFormat = self::DATAFORMAT_DEFLATED; + } + } + } + + return parent::save(); + } + + private function getRawData() { + if ($this->rawData === null) { + $type = $this->getDataType(); + $data = $this->getData(); + + switch ($type) { + case self::DATATYPE_TEXT: + // In this storage type, the changes are stored on the object. + $data = $data; + break; + case self::DATATYPE_FILE: + default: + throw new Exception( + pht('Hunk has unsupported data type "%s"!', $type)); + } + + $format = $this->getDataFormat(); + switch ($format) { + case self::DATAFORMAT_RAW: + // In this format, the changes are stored as-is. + $data = $data; + break; + case self::DATAFORMAT_DEFLATED: + $data = PhabricatorCaches::inflateData($data); + break; + default: + throw new Exception( + pht('Hunk has unsupported data encoding "%s"!', $type)); + } + + $this->rawData = $data; + } + + return $this->rawData; + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */ diff --git a/src/applications/differential/storage/DifferentialLegacyHunk.php b/src/applications/differential/storage/DifferentialLegacyHunk.php deleted file mode 100644 --- a/src/applications/differential/storage/DifferentialLegacyHunk.php +++ /dev/null @@ -1,37 +0,0 @@ - array( - 'changes' => 'text?', - 'oldOffset' => 'uint32', - 'oldLen' => 'uint32', - 'newOffset' => 'uint32', - 'newLen' => 'uint32', - ), - self::CONFIG_KEY_SCHEMA => array( - 'changesetID' => array( - 'columns' => array('changesetID'), - ), - ), - ) + parent::getConfiguration(); - } - - public function getTableName() { - return 'differential_hunk'; - } - - public function getDataEncoding() { - return 'utf8'; - } - - public function forceEncoding($encoding) { - // Not supported, these are always utf8. - return $this; - } - -} diff --git a/src/applications/differential/storage/DifferentialModernHunk.php b/src/applications/differential/storage/DifferentialModernHunk.php deleted file mode 100644 --- a/src/applications/differential/storage/DifferentialModernHunk.php +++ /dev/null @@ -1,126 +0,0 @@ - array( - 'data' => true, - ), - self::CONFIG_COLUMN_SCHEMA => array( - 'dataType' => 'bytes4', - 'dataEncoding' => 'text16?', - 'dataFormat' => 'bytes4', - 'oldOffset' => 'uint32', - 'oldLen' => 'uint32', - 'newOffset' => 'uint32', - 'newLen' => 'uint32', - ), - self::CONFIG_KEY_SCHEMA => array( - 'key_changeset' => array( - 'columns' => array('changesetID'), - ), - 'key_created' => array( - 'columns' => array('dateCreated'), - ), - ), - ) + parent::getConfiguration(); - } - - public function setChanges($text) { - $this->rawData = $text; - - $this->dataEncoding = $this->detectEncodingForStorage($text); - $this->dataType = self::DATATYPE_TEXT; - $this->dataFormat = self::DATAFORMAT_RAW; - $this->data = $text; - - return $this; - } - - public function getChanges() { - return $this->getUTF8StringFromStorage( - $this->getRawData(), - nonempty($this->forcedEncoding, $this->getDataEncoding())); - } - - public function forceEncoding($encoding) { - $this->forcedEncoding = $encoding; - return $this; - } - - public function save() { - - $type = $this->getDataType(); - $format = $this->getDataFormat(); - - // Before saving the data, attempt to compress it. - if ($type == self::DATATYPE_TEXT) { - if ($format == self::DATAFORMAT_RAW) { - $data = $this->getData(); - $deflated = PhabricatorCaches::maybeDeflateData($data); - if ($deflated !== null) { - $this->data = $deflated; - $this->dataFormat = self::DATAFORMAT_DEFLATED; - } - } - } - - return parent::save(); - } - - private function getRawData() { - if ($this->rawData === null) { - $type = $this->getDataType(); - $data = $this->getData(); - - switch ($type) { - case self::DATATYPE_TEXT: - // In this storage type, the changes are stored on the object. - $data = $data; - break; - case self::DATATYPE_FILE: - default: - throw new Exception( - pht('Hunk has unsupported data type "%s"!', $type)); - } - - $format = $this->getDataFormat(); - switch ($format) { - case self::DATAFORMAT_RAW: - // In this format, the changes are stored as-is. - $data = $data; - break; - case self::DATAFORMAT_DEFLATED: - $data = PhabricatorCaches::inflateData($data); - break; - default: - throw new Exception( - pht('Hunk has unsupported data encoding "%s"!', $type)); - } - - $this->rawData = $data; - } - - return $this->rawData; - } - -} diff --git a/src/applications/differential/storage/__tests__/DifferentialHunkTestCase.php b/src/applications/differential/storage/__tests__/DifferentialHunkTestCase.php --- a/src/applications/differential/storage/__tests__/DifferentialHunkTestCase.php +++ b/src/applications/differential/storage/__tests__/DifferentialHunkTestCase.php @@ -5,7 +5,7 @@ public function testMakeChanges() { $root = dirname(__FILE__).'/hunk/'; - $hunk = new DifferentialModernHunk(); + $hunk = new DifferentialHunk(); $hunk->setChanges(Filesystem::readFile($root.'basic.diff')); $hunk->setOldOffset(1); $hunk->setNewOffset(11); @@ -23,7 +23,7 @@ ); $this->assertEqual($added, $hunk->getAddedLines()); - $hunk = new DifferentialModernHunk(); + $hunk = new DifferentialHunk(); $hunk->setChanges(Filesystem::readFile($root.'newline.diff')); $hunk->setOldOffset(1); $hunk->setNewOffset(11); diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php @@ -431,8 +431,8 @@ // -echo "test"; // -(empty line) - $hunk = id(new DifferentialModernHunk())->setChanges($context); - $vs_hunk = id(new DifferentialModernHunk())->setChanges($vs_context); + $hunk = id(new DifferentialHunk())->setChanges($context); + $vs_hunk = id(new DifferentialHunk())->setChanges($vs_context); if ($hunk->makeOldFile() != $vs_hunk->makeOldFile() || $hunk->makeNewFile() != $vs_hunk->makeNewFile()) { return $vs_diff;