summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2012-01-07 07:40:44 -0600
committerNilay Vaish <nilay@cs.wisc.edu>2012-01-07 07:40:44 -0600
commit4b772782871f265cf7372c984ad750803396938c (patch)
treec57c41916af5ed8aec2a85b786341a8a5d6979ce
parent10c2e8ae9ae3f8f41f88fce7de4c2946d23a98fc (diff)
parentabf26fd82850a7e2d123037ebf22dbe03d49fd5a (diff)
downloadgem5-4b772782871f265cf7372c984ad750803396938c.tar.xz
Merged with Nate's commit
-rw-r--r--util/hgfilesize.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/util/hgfilesize.py b/util/hgfilesize.py
new file mode 100644
index 000000000..8b9ad67ea
--- /dev/null
+++ b/util/hgfilesize.py
@@ -0,0 +1,32 @@
+from mercurial import context
+from mercurial.i18n import _
+
+'''
+[extensions]
+hgfilesize=~/m5/incoming/util/hgfilesize.py
+
+[hooks]
+pretxncommit = python:hgfilesize.limit_file_size
+pretxnchangegroup = python:hgfilesize.limit_file_size
+
+[limit_file_size]
+maximum_file_size = 200000
+'''
+
+def limit_file_size(ui, repo, node=None, **kwargs):
+ '''forbid files over a given size'''
+
+ # default limit is 1 MB
+ limit = int(ui.config('limit_file_size', 'maximum_file_size', 1024*1024))
+ existing_tip = context.changectx(repo, node).rev()
+ new_tip = context.changectx(repo, 'tip').rev()
+ for rev in xrange(existing_tip, new_tip + 1):
+ ctx = context.changectx(repo, rev)
+ for f in ctx.files():
+ fctx = ctx.filectx(f)
+ if fctx.size() > limit:
+ ui.write(_('file %s of %s is too large: %d > %d\n') % \
+ (f, ctx, fctx.size(), limit))
+ return True # This is invalid
+
+ return False # Things are OK.