Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97212141
DiffusionPreCommitContentSizeHeraldField.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 3, 12:09
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Jan 5, 12:09 (2 d)
Engine
blob
Format
Raw Data
Handle
23285872
Attached To
rPH Phabricator
DiffusionPreCommitContentSizeHeraldField.php
View Options
<?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
Log In to Comment