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

Apply the new patch byte size limit to mail patch generation in Differential

Summary: Ref T13137. See PHI592. Depends on D19444. Apply a limit up front to stop patches which are way too big (e.g., 600MB of videos) from generating in the first place.

Test Plan:
- Configured inline patches in git format.
- Created a normal revision, got an inline git patch.
- Created a revision with a 10MB video file, got no inline patch.
- (Added a bunch of debugging stuff to make sure the internal pathway was working.)

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13137

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

+25 -6
+10 -4
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 682 682 if ($config_inline || $config_attach) { 683 683 $body_limit = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); 684 684 685 - $patch = $this->buildPatchForMail($diff); 686 - if ($config_inline) { 685 + try { 686 + $patch = $this->buildPatchForMail($diff, $body_limit); 687 + } catch (ArcanistDiffByteSizeException $ex) { 688 + $patch = null; 689 + } 690 + 691 + if (($patch !== null) && $config_inline) { 687 692 $lines = substr_count($patch, "\n"); 688 693 $bytes = strlen($patch); 689 694 ··· 706 711 } 707 712 } 708 713 709 - if ($config_attach) { 714 + if (($patch !== null) && $config_attach) { 710 715 // See T12033, T11767, and PHI55. This is a crude fix to stop the 711 716 // major concrete problems that lackluster email size limits cause. 712 717 if (strlen($patch) < $body_limit) { ··· 1411 1416 array('style' => 'font-family: monospace;'), $patch); 1412 1417 } 1413 1418 1414 - private function buildPatchForMail(DifferentialDiff $diff) { 1419 + private function buildPatchForMail(DifferentialDiff $diff, $byte_limit) { 1415 1420 $format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'); 1416 1421 1417 1422 return id(new DifferentialRawDiffRenderer()) 1418 1423 ->setViewer($this->getActor()) 1419 1424 ->setFormat($format) 1420 1425 ->setChangesets($diff->getChangesets()) 1426 + ->setByteLimit($byte_limit) 1421 1427 ->buildPatch(); 1422 1428 } 1423 1429
+15 -2
src/applications/differential/render/DifferentialRawDiffRenderer.php
··· 5 5 private $changesets; 6 6 private $format = 'unified'; 7 7 private $viewer; 8 + private $byteLimit; 8 9 9 10 public function setFormat($format) { 10 11 $this->format = $format; ··· 35 36 return $this->viewer; 36 37 } 37 38 39 + public function setByteLimit($byte_limit) { 40 + $this->byteLimit = $byte_limit; 41 + return $this; 42 + } 43 + 44 + public function getByteLimit() { 45 + return $this->byteLimit; 46 + } 47 + 38 48 public function buildPatch() { 39 49 $diff = new DifferentialDiff(); 40 50 $diff->attachChangesets($this->getChangesets()); ··· 52 62 $bundle = ArcanistBundle::newFromChanges($changes); 53 63 $bundle->setLoadFileDataCallback(array($loader, 'loadFileData')); 54 64 65 + $byte_limit = $this->getByteLimit(); 66 + if ($byte_limit) { 67 + $bundle->setByteLimit($byte_limit); 68 + } 69 + 55 70 $format = $this->getFormat(); 56 71 switch ($format) { 57 72 case 'git': 58 73 return $bundle->toGitPatch(); 59 - break; 60 74 case 'unified': 61 75 default: 62 76 return $bundle->toUnifiedDiff(); 63 - break; 64 77 } 65 78 } 66 79 }