Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
| Show All 31 Lines | final class DiffusionCommitHookEngine extends Phobject { | ||||
| private $mercurialCommits = array(); | private $mercurialCommits = array(); | ||||
| private $gitCommits = array(); | private $gitCommits = array(); | ||||
| private $heraldViewerProjects; | private $heraldViewerProjects; | ||||
| private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; | private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; | ||||
| private $rejectDetails; | private $rejectDetails; | ||||
| private $emailPHIDs = array(); | private $emailPHIDs = array(); | ||||
| private $changesets = array(); | private $changesets = array(); | ||||
| private $changesetsSize = 0; | |||||
| /* -( Config )------------------------------------------------------------- */ | /* -( Config )------------------------------------------------------------- */ | ||||
| public function setRemoteProtocol($remote_protocol) { | public function setRemoteProtocol($remote_protocol) { | ||||
| $this->remoteProtocol = $remote_protocol; | $this->remoteProtocol = $remote_protocol; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 1,068 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
| } | } | ||||
| private function rejectEnormousChanges(array $content_updates) { | private function rejectEnormousChanges(array $content_updates) { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| if ($repository->shouldAllowEnormousChanges()) { | if ($repository->shouldAllowEnormousChanges()) { | ||||
| return; | return; | ||||
| } | } | ||||
| // See T13142. Don't cache more than 64MB of changesets. For normal small | |||||
| // pushes, caching everything here can let us hit the cache from Herald if | |||||
| // we need to run content rules, which speeds things up a bit. For large | |||||
| // pushes, we may not be able to hold everything in memory. | |||||
| $cache_limit = 1024 * 1024 * 64; | |||||
| foreach ($content_updates as $update) { | foreach ($content_updates as $update) { | ||||
| $identifier = $update->getRefNew(); | $identifier = $update->getRefNew(); | ||||
| try { | try { | ||||
| $changesets = $this->loadChangesetsForCommit($identifier); | $info = $this->loadChangesetsForCommit($identifier); | ||||
| list($changesets, $size) = $info; | |||||
| if ($this->changesetsSize + $size <= $cache_limit) { | |||||
| $this->changesets[$identifier] = $changesets; | $this->changesets[$identifier] = $changesets; | ||||
| $this->changesetsSize += $size; | |||||
| } | |||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $this->changesets[$identifier] = $ex; | $this->changesets[$identifier] = $ex; | ||||
| $message = pht( | $message = pht( | ||||
| 'ENORMOUS CHANGE'. | 'ENORMOUS CHANGE'. | ||||
| "\n". | "\n". | ||||
| 'Enormous change protection is enabled for this repository, but '. | 'Enormous change protection is enabled for this repository, but '. | ||||
| 'you are pushing an enormous change ("%s"). Edit the repository '. | 'you are pushing an enormous change ("%s"). Edit the repository '. | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (!strlen($raw_diff)) { | ||||
| // If the commit is actually empty, just return no changesets. | // If the commit is actually empty, just return no changesets. | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $parser = new ArcanistDiffParser(); | $parser = new ArcanistDiffParser(); | ||||
| $changes = $parser->parseDiff($raw_diff); | $changes = $parser->parseDiff($raw_diff); | ||||
| $diff = DifferentialDiff::newEphemeralFromRawChanges( | $diff = DifferentialDiff::newEphemeralFromRawChanges( | ||||
| $changes); | $changes); | ||||
| return $diff->getChangesets(); | |||||
| $changesets = $diff->getChangesets(); | |||||
| $size = strlen($raw_diff); | |||||
| return array($changesets, $size); | |||||
| } | } | ||||
| public function getChangesetsForCommit($identifier) { | public function getChangesetsForCommit($identifier) { | ||||
| if (isset($this->changesets[$identifier])) { | if (isset($this->changesets[$identifier])) { | ||||
| $cached = $this->changesets[$identifier]; | $cached = $this->changesets[$identifier]; | ||||
| if ($cached instanceof Exception) { | if ($cached instanceof Exception) { | ||||
| throw $cached; | throw $cached; | ||||
| } | } | ||||
| return $cached; | return $cached; | ||||
| } | } | ||||
| return $this->loadChangesetsForCommit($identifier); | $info = $this->loadChangesetsForCommit($identifier); | ||||
| list($changesets, $size) = $info; | |||||
| return $changesets; | |||||
| } | } | ||||
| public function loadCommitRefForCommit($identifier) { | public function loadCommitRefForCommit($identifier) { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $vcs = $repository->getVersionControlSystem(); | $vcs = $repository->getVersionControlSystem(); | ||||
| switch ($vcs) { | switch ($vcs) { | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: | case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: | case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: | ||||
| ▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines | |||||