@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.

Make "metamta.differential.inline-patches" imply a reasonable byte limit, not just a line limit

Summary:
Fixes T11748. This option currently implies a line limit (e.g., inline patches that are less than 100 lines long). This breaks down if a diff has a 10MB line, like a huge blob of JSON all on one line.

For now, imply a reasonable byte limit (256 bytes per line).

See T11767 for future work to make this and related options more cohesive.

Test Plan:
- With option at `1000`: sent Differential email, saw patches inlined.
- With option at `10`: sent Differential email, saw patches dropped because of the byte limit.
- `var_dump()`'d the actual limits and used `bin/worker execute --id ...` to sanity check that things were working properly.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11748

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

+36 -10
+14 -7
src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
··· 70 70 ); 71 71 } 72 72 73 + $inline_description = $this->deformat( 74 + pht(<<<EOHELP 75 + To include patches inline in email bodies, set this option to a positive 76 + integer. Patches will be inlined if they are at most that many lines and at 77 + most 256 times that many bytes. 78 + 79 + For example, a value of 100 means "inline patches if they are at not more than 80 + 100 lines long and not more than 25,600 bytes large". 81 + 82 + By default, patches are not inlined. 83 + EOHELP 84 + )); 85 + 73 86 return array( 74 87 $this->newOption( 75 88 'differential.fields', ··· 254 267 'int', 255 268 0) 256 269 ->setSummary(pht('Inline patches in email, as body text.')) 257 - ->setDescription( 258 - pht( 259 - "To include patches inline in email bodies, set this to a ". 260 - "positive integer. Patches will be inlined if they are at most ". 261 - "that many lines. For instance, a value of 100 means 'inline ". 262 - "patches if they are no longer than 100 lines'. By default, ". 263 - "patches are not inlined.")), 270 + ->setDescription($inline_description), 264 271 $this->newOption( 265 272 'metamta.differential.patch-format', 266 273 'enum',
+22 -3
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 1264 1264 $config_attach = PhabricatorEnv::getEnvConfig($config_key_attach); 1265 1265 1266 1266 if ($config_inline || $config_attach) { 1267 + $body_limit = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); 1268 + 1267 1269 $patch = $this->buildPatchForMail($diff); 1268 - $lines = substr_count($patch, "\n"); 1270 + if ($config_inline) { 1271 + $lines = substr_count($patch, "\n"); 1272 + $bytes = strlen($patch); 1273 + 1274 + // Limit the patch size to the smaller of 256 bytes per line or 1275 + // the mail body limit. This prevents degenerate behavior for patches 1276 + // with one line that is 10MB long. See T11748. 1277 + $byte_limits = array(); 1278 + $byte_limits[] = (256 * $config_inline); 1279 + $byte_limits[] = $body_limit; 1280 + $byte_limit = min($byte_limits); 1269 1281 1270 - if ($config_inline && ($lines <= $config_inline)) { 1271 - $this->appendChangeDetailsForMail($object, $diff, $patch, $body); 1282 + $lines_ok = ($lines <= $config_inline); 1283 + $bytes_ok = ($bytes <= $byte_limit); 1284 + 1285 + if ($lines_ok && $bytes_ok) { 1286 + $this->appendChangeDetailsForMail($object, $diff, $patch, $body); 1287 + } else { 1288 + // TODO: Provide a helpful message about the patch being too 1289 + // large or lengthy here. 1290 + } 1272 1291 } 1273 1292 1274 1293 if ($config_attach) {