@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Increase the storage size for commit summaries

Summary:
Fixes T11453. Currently, commit message summaries are limited to 80 bytes. This may only be 20-40 characters for CJK languages or langauges with Cyrillic script.

Increase storage size to 255, then truncate to the shorter of 255 bytes or 80 glyphs. This preserves the same behavior for latin languages, but is less tight for Russian, etc.

Some minor additional changes:

- Provide a way to ask "how much data fits in this column?" so we don't have to duplicate column lengths across summary checks or UI errors like "title too long".
- Remove the `text80` datatype, since no other columns use it and we have no use cases (or likely use cases) for it.

Test Plan:
- Made a commit with a Cyrillic title, saw reasonable summarization in UI:

{F1757522}

- Added and ran unit tests.
- Grepped for removed `SUMMARY_MAX_LENGTH` constant.
- Grepped for removed `text80` data type.

Reviewers: avivey, chad

Reviewed By: avivey

Subscribers: avivey

Maniphest Tasks: T11453

Differential Revision: https://secure.phabricator.com/D16385

+89 -12
+2
resources/sql/autopatches/20160810.commit.01.summarylength.sql
··· 1 + ALTER TABLE {$NAMESPACE}_repository.repository_commit 2 + CHANGE summary summary VARCHAR(255) NOT NULL COLLATE {$COLLATE_TEXT};
+2
src/__phutil_library_map__.php
··· 3381 3381 'PhabricatorRepositoryCommitPHIDType' => 'applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php', 3382 3382 'PhabricatorRepositoryCommitParserWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php', 3383 3383 'PhabricatorRepositoryCommitRef' => 'applications/repository/engine/PhabricatorRepositoryCommitRef.php', 3384 + 'PhabricatorRepositoryCommitTestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryCommitTestCase.php', 3384 3385 'PhabricatorRepositoryConfigOptions' => 'applications/repository/config/PhabricatorRepositoryConfigOptions.php', 3385 3386 'PhabricatorRepositoryDAO' => 'applications/repository/storage/PhabricatorRepositoryDAO.php', 3386 3387 'PhabricatorRepositoryDiscoveryEngine' => 'applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php', ··· 8338 8339 'PhabricatorRepositoryCommitPHIDType' => 'PhabricatorPHIDType', 8339 8340 'PhabricatorRepositoryCommitParserWorker' => 'PhabricatorWorker', 8340 8341 'PhabricatorRepositoryCommitRef' => 'Phobject', 8342 + 'PhabricatorRepositoryCommitTestCase' => 'PhabricatorTestCase', 8341 8343 'PhabricatorRepositoryConfigOptions' => 'PhabricatorApplicationConfigOptions', 8342 8344 'PhabricatorRepositoryDAO' => 'PhabricatorLiskDAO', 8343 8345 'PhabricatorRepositoryDiscoveryEngine' => 'PhabricatorRepositoryEngine',
+24 -3
src/applications/config/schema/PhabricatorConfigSchemaSpec.php
··· 70 70 } 71 71 72 72 $details = $this->getDetailsForDataType($type); 73 - list($column_type, $charset, $collation, $nullable, $auto) = $details; 73 + 74 + $column_type = $details['type']; 75 + $charset = $details['charset']; 76 + $collation = $details['collation']; 77 + $nullable = $details['nullable']; 78 + $auto = $details['auto']; 74 79 75 80 $column = $this->newColumn($name) 76 81 ->setDataType($type) ··· 182 187 ->setName($name); 183 188 } 184 189 190 + public function getMaximumByteLengthForDataType($data_type) { 191 + $info = $this->getDetailsForDataType($data_type); 192 + return idx($info, 'bytes'); 193 + } 194 + 185 195 private function getDetailsForDataType($data_type) { 186 196 $column_type = null; 187 197 $charset = null; 188 198 $collation = null; 189 199 $auto = false; 200 + $bytes = null; 190 201 191 202 // If the type ends with "?", make the column nullable. 192 203 $nullable = false; ··· 211 222 'text255' => true, 212 223 'text160' => true, 213 224 'text128' => true, 214 - 'text80' => true, 215 225 'text64' => true, 216 226 'text40' => true, 217 227 'text32' => true, ··· 237 247 $type = $matches[1]; 238 248 $size = idx($matches, 2); 239 249 250 + if ($size) { 251 + $bytes = $size; 252 + } 253 + 240 254 switch ($type) { 241 255 case 'text': 242 256 if ($is_binary) { ··· 363 377 } 364 378 } 365 379 366 - return array($column_type, $charset, $collation, $nullable, $auto); 380 + return array( 381 + 'type' => $column_type, 382 + 'charset' => $charset, 383 + 'collation' => $collation, 384 + 'nullable' => $nullable, 385 + 'auto' => $auto, 386 + 'bytes' => $bytes, 387 + ); 367 388 } 368 389 369 390 }
+1 -1
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 108 108 'mailKey' => 'bytes20', 109 109 'authorPHID' => 'phid?', 110 110 'auditStatus' => 'uint32', 111 - 'summary' => 'text80', 111 + 'summary' => 'text255', 112 112 'importStatus' => 'uint32', 113 113 ), 114 114 self::CONFIG_KEY_SCHEMA => array(
+5 -7
src/applications/repository/storage/PhabricatorRepositoryCommitData.php
··· 2 2 3 3 final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO { 4 4 5 - /** 6 - * NOTE: We denormalize this into the commit table; make sure the sizes 7 - * match up. 8 - */ 9 - const SUMMARY_MAX_LENGTH = 80; 10 - 11 5 protected $commitID; 12 6 protected $authorName = ''; 13 7 protected $commitMessage = ''; ··· 38 32 } 39 33 40 34 public static function summarizeCommitMessage($message) { 35 + $max_bytes = id(new PhabricatorRepositoryCommit()) 36 + ->getColumnMaximumByteLength('summary'); 37 + 41 38 $summary = phutil_split_lines($message, $retain_endings = false); 42 39 $summary = head($summary); 43 40 $summary = id(new PhutilUTF8StringTruncator()) 44 - ->setMaximumBytes(self::SUMMARY_MAX_LENGTH) 41 + ->setMaximumBytes($max_bytes) 42 + ->setMaximumGlyphs(80) 45 43 ->truncateString($summary); 46 44 47 45 return $summary;
+38
src/applications/repository/storage/__tests__/PhabricatorRepositoryCommitTestCase.php
··· 1 + <?php 2 + 3 + final class PhabricatorRepositoryCommitTestCase 4 + extends PhabricatorTestCase { 5 + 6 + public function testSummarizeCommits() { 7 + // Cyrillic "zhe". 8 + $zhe = "\xD0\xB6"; 9 + 10 + // Symbol "Snowman". 11 + $snowman = "\xE2\x98\x83"; 12 + 13 + // Emoji "boar". 14 + $boar = "\xF0\x9F\x90\x97"; 15 + 16 + // Proper unicode truncation is tested elsewhere, this is just making 17 + // sure column length handling is sane. 18 + 19 + $map = array( 20 + '' => 0, 21 + 'a' => 1, 22 + str_repeat('a', 81) => 82, 23 + str_repeat('a', 255) => 82, 24 + str_repeat('aa ', 30) => 80, 25 + str_repeat($zhe, 300) => 161, 26 + str_repeat($snowman, 300) => 240, 27 + str_repeat($boar, 300) => 255, 28 + ); 29 + 30 + foreach ($map as $input => $expect) { 31 + $actual = PhabricatorRepositoryCommitData::summarizeCommitMessage( 32 + $input); 33 + $this->assertEqual($expect, strlen($actual)); 34 + } 35 + 36 + } 37 + 38 + }
+17 -1
src/infrastructure/storage/lisk/LiskDAO.php
··· 1831 1831 return $this->getConfigOption(self::CONFIG_BINARY); 1832 1832 } 1833 1833 1834 - 1835 1834 public function getSchemaColumns() { 1836 1835 $custom_map = $this->getConfigOption(self::CONFIG_COLUMN_SCHEMA); 1837 1836 if (!$custom_map) { ··· 1951 1950 } 1952 1951 1953 1952 return $custom_map + $default_map; 1953 + } 1954 + 1955 + public function getColumnMaximumByteLength($column) { 1956 + $map = $this->getSchemaColumns(); 1957 + 1958 + if (!isset($map[$column])) { 1959 + throw new Exception( 1960 + pht( 1961 + 'Object (of class "%s") does not have a column "%s".', 1962 + get_class($this), 1963 + $column)); 1964 + } 1965 + 1966 + $data_type = $map[$column]; 1967 + 1968 + return id(new PhabricatorStorageSchemaSpec()) 1969 + ->getMaximumByteLengthForDataType($data_type); 1954 1970 } 1955 1971 1956 1972 }