Rev 6380: Migrate add.maximum_file_size to the new config scheme in file:///home/vila/src/bzr/experimental/config-si-unit/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Dec 16 16:38:33 UTC 2011
At file:///home/vila/src/bzr/experimental/config-si-unit/
------------------------------------------------------------
revno: 6380
revision-id: v.ladeuil+lp at free.fr-20111216163833-4igwmwi1dmxbbebw
parent: v.ladeuil+lp at free.fr-20111216162001-qe39b3khelh34u1v
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-si-unit
timestamp: Fri 2011-12-16 17:38:33 +0100
message:
Migrate add.maximum_file_size to the new config scheme
-------------- next part --------------
=== modified file 'bzrlib/add.py'
--- a/bzrlib/add.py 2011-09-16 12:04:16 +0000
+++ b/bzrlib/add.py 2011-12-16 16:38:33 +0000
@@ -73,27 +73,25 @@
class AddWithSkipLargeAction(AddAction):
"""A class that can decide to skip a file if it's considered too large"""
- # default 20 MB
- _DEFAULT_MAX_FILE_SIZE = 20000000
- _optionName = 'add.maximum_file_size'
_maxSize = None
def skip_file(self, tree, path, kind, stat_value = None):
if kind != 'file':
- return False
+ return False
+ opt_name = 'add.maximum_file_size'
if self._maxSize is None:
- config = tree.branch.get_config()
- self._maxSize = config.get_user_option_as_int_from_SI(
- self._optionName,
- self._DEFAULT_MAX_FILE_SIZE)
+ # FIXME: We use the branch config as there is no tree config
+ # -- vila 2011-12-16
+ config = tree.branch.get_config_stack()
+ self._maxSize = config.get(opt_name)
if stat_value is None:
file_size = os.path.getsize(path);
else:
file_size = stat_value.st_size;
if self._maxSize > 0 and file_size > self._maxSize:
ui.ui_factory.show_warning(gettext(
- "skipping {0} (larger than {1} of {2} bytes)").format(
- path, self._optionName, self._maxSize))
+ "skipping {0} (larger than {1} ({2} bytes))").format(
+ path, opt_name, self._maxSize))
return True
return False
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-12-16 16:20:01 +0000
+++ b/bzrlib/config.py 2011-12-16 16:38:33 +0000
@@ -440,6 +440,7 @@
l = [l]
return l
+ @deprecated_method(deprecated_in((2, 5, 0)))
def get_user_option_as_int_from_SI(self, option_name, default=None):
"""Get a generic option from a human readable size in SI units, e.g 10MB
@@ -2458,6 +2459,15 @@
_unit_sfxs = dict(K=10**3, M=10**6, G=10**9)
def int_SI_from_store(unicode_str):
+ """Convert a human readable size in SI units, e.g 10MB into an integer.
+
+ Accepted suffixes are K,M,G. It is case-insensitive and may be followed
+ by a trailing b (i.e. Kb, MB). This is intended to be practical and not
+ pedantic.
+
+ :return Integer, expanded to its base-10 value if a proper SI unit is
+ found, None otherwise.
+ """
regexp = "^(\d+)(([" + ''.join(_unit_sfxs) + "])b?)?$"
p = re.compile(regexp, re.IGNORECASE)
m = p.match(unicode_str)
@@ -2558,6 +2568,16 @@
List of GPG key patterns which are acceptable for verification.
"""))
option_registry.register(
+ Option('add.maximum_file_size',
+ default=u'20MB', from_unicode=int_SI_from_store,
+ help="""Size above which files should be added manually.
+
+Files below this size are added automatically when using ``bzr add`` without
+arguments.
+
+A negative value means disable the size check.
+"""))
+option_registry.register(
Option('bzr.workingtree.worth_saving_limit', default=10,
from_unicode=int_from_store, invalid='warning',
help='''\
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-12-16 16:20:01 +0000
+++ b/bzrlib/tests/test_config.py 2011-12-16 16:38:33 +0000
@@ -1069,7 +1069,10 @@
si_g = 5g,
si_gb = 5gB,
""")
- get_si = conf.get_user_option_as_int_from_SI
+ def get_si(s, default=None):
+ return self.applyDeprecated(
+ deprecated_in((2, 5, 0)),
+ conf.get_user_option_as_int_from_SI, s, default)
self.assertEqual(100, get_si('plain'))
self.assertEqual(5000, get_si('si_k'))
self.assertEqual(5000, get_si('si_kb'))
More information about the bazaar-commits
mailing list