@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 "enormous changes" rules to pre-commit content rules too

Summary:
Fixes T4276. This adds "Change is enormous" to pre-commit content rules so we can, e.g., just reject these and not worry about them elsewhere.

Also, use the same numeric limits across the mechanisms so there's a consistent definition of an "enormous" changeset.

Test Plan:
- Set enormous limit to 15 bytes, pushed some changes, got blocked by a rule.
- Set it back, pushed OK.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4276

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

+36 -5
+21 -2
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 1004 1004 } 1005 1005 1006 1006 public function loadChangesetsForCommit($identifier) { 1007 + $byte_limit = HeraldCommitAdapter::getEnormousByteLimit(); 1008 + $time_limit = HeraldCommitAdapter::getEnormousTimeLimit(); 1009 + 1007 1010 $vcs = $this->getRepository()->getVersionControlSystem(); 1008 1011 switch ($vcs) { 1009 1012 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: ··· 1015 1018 'user' => $this->getViewer(), 1016 1019 'commit' => $identifier, 1017 1020 )); 1021 + 1018 1022 $raw_diff = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest) 1019 - ->setTimeout(5 * 60) 1023 + ->setTimeout($time_limit) 1024 + ->setByteLimit($byte_limit) 1020 1025 ->setLinesOfContext(0) 1021 1026 ->loadRawDiff(); 1022 1027 break; ··· 1027 1032 // the "--diff-cmd" flag. 1028 1033 1029 1034 // For subversion, we need to use `svnlook`. 1030 - list($raw_diff) = execx( 1035 + $future = new ExecFuture( 1031 1036 'svnlook diff -t %s %s', 1032 1037 $this->subversionTransaction, 1033 1038 $this->subversionRepository); 1039 + 1040 + $future->setTimeout($time_limit); 1041 + $future->setStdoutSizeLimit($byte_limit); 1042 + $future->setStderrSizeLimit($byte_limit); 1043 + 1044 + list($raw_diff) = $future->resolvex(); 1034 1045 break; 1035 1046 default: 1036 1047 throw new Exception(pht("Unknown VCS '%s!'", $vcs)); 1048 + } 1049 + 1050 + if (strlen($raw_diff) >= $byte_limit) { 1051 + throw new Exception( 1052 + pht( 1053 + 'The raw text of this change is enormous (larger than %d '. 1054 + 'bytes). Herald can not process it.', 1055 + $byte_limit)); 1037 1056 } 1038 1057 1039 1058 $parser = new ArcanistDiffParser();
+4
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 34 34 self::FIELD_DIFF_CONTENT, 35 35 self::FIELD_DIFF_ADDED_CONTENT, 36 36 self::FIELD_DIFF_REMOVED_CONTENT, 37 + self::FIELD_DIFF_ENORMOUS, 37 38 self::FIELD_REPOSITORY, 38 39 self::FIELD_REPOSITORY_PROJECTS, 39 40 self::FIELD_PUSHER, ··· 75 76 return $this->getDiffContent('+'); 76 77 case self::FIELD_DIFF_REMOVED_CONTENT: 77 78 return $this->getDiffContent('-'); 79 + case self::FIELD_DIFF_ENORMOUS: 80 + $this->getDiffContent('*'); 81 + return ($this->changesets instanceof Exception); 78 82 case self::FIELD_REPOSITORY: 79 83 return $this->getHookEngine()->getRepository()->getPHID(); 80 84 case self::FIELD_REPOSITORY_PROJECTS:
+10 -2
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 270 270 return $this->affectedRevision; 271 271 } 272 272 273 + public static function getEnormousByteLimit() { 274 + return 1024 * 1024 * 1024; // 1GB 275 + } 276 + 277 + public static function getEnormousTimeLimit() { 278 + return 60 * 15; // 15 Minutes 279 + } 280 + 273 281 private function loadCommitDiff() { 274 282 $drequest = DiffusionRequest::newFromDictionary( 275 283 array( ··· 278 286 'commit' => $this->commit->getCommitIdentifier(), 279 287 )); 280 288 281 - $byte_limit = (1024 * 1024 * 1024); // 1GB 289 + $byte_limit = self::getEnormousByteLimit(); 282 290 283 291 $raw = DiffusionQuery::callConduitWithDiffusionRequest( 284 292 PhabricatorUser::getOmnipotentUser(), ··· 286 294 'diffusion.rawdiffquery', 287 295 array( 288 296 'commit' => $this->commit->getCommitIdentifier(), 289 - 'timeout' => (60 * 15), // 15 minutes 297 + 'timeout' => self::getEnormousTimeLimit(), 290 298 'byteLimit' => $byte_limit, 291 299 'linesOfContext' => 0, 292 300 ));
+1 -1
src/applications/herald/storage/HeraldRule.php
··· 17 17 protected $isDisabled = 0; 18 18 protected $triggerObjectPHID; 19 19 20 - protected $configVersion = 25; 20 + protected $configVersion = 26; 21 21 22 22 // phids for which this rule has been applied 23 23 private $ruleApplied = self::ATTACHABLE;