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
This commit is contained in:
epriestley
2014-01-06 12:12:30 -08:00
parent cba959635e
commit 3627e73e5e
4 changed files with 36 additions and 5 deletions

View File

@@ -1004,6 +1004,9 @@ final class DiffusionCommitHookEngine extends Phobject {
}
public function loadChangesetsForCommit($identifier) {
$byte_limit = HeraldCommitAdapter::getEnormousByteLimit();
$time_limit = HeraldCommitAdapter::getEnormousTimeLimit();
$vcs = $this->getRepository()->getVersionControlSystem();
switch ($vcs) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
@@ -1015,8 +1018,10 @@ final class DiffusionCommitHookEngine extends Phobject {
'user' => $this->getViewer(),
'commit' => $identifier,
));
$raw_diff = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest)
->setTimeout(5 * 60)
->setTimeout($time_limit)
->setByteLimit($byte_limit)
->setLinesOfContext(0)
->loadRawDiff();
break;
@@ -1027,15 +1032,29 @@ final class DiffusionCommitHookEngine extends Phobject {
// the "--diff-cmd" flag.
// For subversion, we need to use `svnlook`.
list($raw_diff) = execx(
$future = new ExecFuture(
'svnlook diff -t %s %s',
$this->subversionTransaction,
$this->subversionRepository);
$future->setTimeout($time_limit);
$future->setStdoutSizeLimit($byte_limit);
$future->setStderrSizeLimit($byte_limit);
list($raw_diff) = $future->resolvex();
break;
default:
throw new Exception(pht("Unknown VCS '%s!'", $vcs));
}
if (strlen($raw_diff) >= $byte_limit) {
throw new Exception(
pht(
'The raw text of this change is enormous (larger than %d '.
'bytes). Herald can not process it.',
$byte_limit));
}
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);