Differential D16460 Diff 39599 src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
| Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | protected function parseCommit( | ||||
| $editor->setRawPatch($raw_patch); | $editor->setRawPatch($raw_patch); | ||||
| return $editor->applyTransactions($commit, $xactions); | return $editor->applyTransactions($commit, $xactions); | ||||
| } | } | ||||
| private function loadRawPatchText( | private function loadRawPatchText( | ||||
| PhabricatorRepository $repository, | PhabricatorRepository $repository, | ||||
| PhabricatorRepositoryCommit $commit) { | PhabricatorRepositoryCommit $commit) { | ||||
| $viewer = PhabricatorUser::getOmnipotentUser(); | |||||
| $identifier = $commit->getCommitIdentifier(); | |||||
| $drequest = DiffusionRequest::newFromDictionary( | $drequest = DiffusionRequest::newFromDictionary( | ||||
| array( | array( | ||||
| 'user' => PhabricatorUser::getOmnipotentUser(), | 'user' => $viewer, | ||||
| 'repository' => $repository, | 'repository' => $repository, | ||||
| 'commit' => $commit->getCommitIdentifier(), | |||||
| )); | )); | ||||
| $raw_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest); | |||||
| $raw_query->setLinesOfContext(3); | |||||
| $time_key = 'metamta.diffusion.time-limit'; | $time_key = 'metamta.diffusion.time-limit'; | ||||
| $byte_key = 'metamta.diffusion.byte-limit'; | $byte_key = 'metamta.diffusion.byte-limit'; | ||||
| $time_limit = PhabricatorEnv::getEnvConfig($time_key); | $time_limit = PhabricatorEnv::getEnvConfig($time_key); | ||||
| $byte_limit = PhabricatorEnv::getEnvConfig($byte_key); | $byte_limit = PhabricatorEnv::getEnvConfig($byte_key); | ||||
| if ($time_limit) { | $diff_info = DiffusionQuery::callConduitWithDiffusionRequest( | ||||
| $raw_query->setTimeout($time_limit); | $viewer, | ||||
| } | $drequest, | ||||
| 'diffusion.rawdiffquery', | |||||
| array( | |||||
| 'commit' => $identifier, | |||||
| 'linesOfContext' => 3, | |||||
| 'timeout' => $time_limit, | |||||
| 'byteLimit' => $byte_limit, | |||||
| )); | |||||
| $raw_diff = $raw_query->loadRawDiff(); | if ($diff_info['tooSlow']) { | ||||
| throw new Exception( | |||||
| pht( | |||||
| 'Patch generation took longer than configured limit ("%s") of '. | |||||
| '%s second(s).', | |||||
| $time_key, | |||||
| new PhutilNumber($time_limit))); | |||||
| } | |||||
| $size = strlen($raw_diff); | if ($diff_info['tooHuge']) { | ||||
| if ($byte_limit && $size > $byte_limit) { | |||||
| $pretty_size = phutil_format_bytes($size); | |||||
| $pretty_limit = phutil_format_bytes($byte_limit); | $pretty_limit = phutil_format_bytes($byte_limit); | ||||
| throw new Exception(pht( | throw new Exception( | ||||
| 'Patch size of %s exceeds configured byte size limit (%s) of %s.', | pht( | ||||
| $pretty_size, | 'Patch size exceeds configured byte size limit ("%s") of %s.', | ||||
| $byte_key, | $byte_key, | ||||
| $pretty_limit)); | $pretty_limit)); | ||||
| } | } | ||||
| return $raw_diff; | $file_phid = $diff_info['filePHID']; | ||||
| $file = id(new PhabricatorFileQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs(array($file_phid)) | |||||
| ->executeOne(); | |||||
| if (!$file) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Failed to load file ("%s") returned by "%s".', | |||||
| $file_phid, | |||||
| 'diffusion.rawdiffquery')); | |||||
| } | |||||
| return $file->loadFileData(); | |||||
| } | } | ||||
| } | } | ||||