Page MenuHomec4science

DiffusionPreCommitContentSizeHeraldField.php
No OneTemporary

File Metadata

Created
Tue, Jun 4, 09:45

DiffusionPreCommitContentSizeHeraldField.php

<?php
final class DiffusionPreCommitContentSizeHeraldField
extends DiffusionPreCommitContentHeraldField {
const FIELDCONST = 'diffusion.pre.content.diff.size';
const MAX_SIZE = 33554432; // 32M
public function getHeraldFieldName() {
return pht('Diff size exceeded');
}
public function getFieldGroupKey() {
return DiffusionChangeHeraldFieldGroup::FIELDGROUPKEY;
}
public function getHeraldFieldValue($object) {
$adapter = $this->getAdapter();
$hook = $adapter->getHookEngine();
$repository = $hook->getRepository();
$vcs = $repository->getVersionControlSystem();
if($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) {
$ref = $adapter->getObject()->getRefNew();
$changesets = $hook->loadChangesetsForCommit($ref);
$total_size = 0;
foreach($changesets as $change){
$size = exec("git cat-file -s $ref:" . $change->getFileName());
$total_size += (int) $size;
}
if($total_size >= self::MAX_SIZE) {
return true;
}
}
return false;
}
protected function getHeraldFieldStandardType() {
return HeraldField::STANDARD_BOOL;
}
}

Event Timeline