1 from mercurial
import context
2 from mercurial
.i18n
import _
6 hgfilesize=~/m5/incoming/util/hgfilesize.py
9 pretxncommit = python:hgfilesize.limit_file_size
10 pretxnchangegroup = python:hgfilesize.limit_file_size
13 maximum_file_size = 200000
16 def limit_file_size(ui
, repo
, node
=None, **kwargs
):
17 '''forbid files over a given size'''
19 # default limit is 1 MB
20 limit
= int(ui
.config('limit_file_size', 'maximum_file_size', 1024*1024))
21 existing_tip
= context
.changectx(repo
, node
).rev()
22 new_tip
= context
.changectx(repo
, 'tip').rev()
23 for rev
in xrange(existing_tip
, new_tip
+ 1):
24 ctx
= context
.changectx(repo
, rev
)
29 if fctx
.size() > limit
:
30 ui
.write(_('file %s of %s is too large: %d > %d\n') % \
31 (f
, ctx
, fctx
.size(), limit
))
32 return True # This is invalid
34 return False # Things are OK.