Commit 510162b7 authored by Ximin Luo's avatar Ximin Luo

config: force-set a value if it must be < another, and it was not set on purpose (Closes: #875451)

parent f5c9986b
......@@ -19,19 +19,29 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import logging
logger = logging.getLogger(__name__)
class defaultint(int):
pass
class Config(object):
# GNU diff cannot process arbitrary large files :(
max_diff_input_lines = 2 ** 22
max_diff_block_lines_saved = float("inf")
# hard limits, restricts single-file and multi-file formats
max_report_size = 40 * 2 ** 20 # 40 MB
max_diff_block_lines = 2 ** 10 # 1024 lines
max_report_size = defaultint(40 * 2 ** 20) # 40 MB
max_diff_block_lines = defaultint(2 ** 10) # 1024 lines
# structural limits, restricts single-file formats
# semi-restricts multi-file formats
max_page_size = 400 * 2 ** 10 # 400 kB
max_page_size_child = 200 * 2 ** 10 # 200 kB
max_page_diff_block_lines = 2 ** 7 # 128 lines
max_page_size = defaultint(400 * 2 ** 10) # 400 kB
max_page_size_child = defaultint(200 * 2 ** 10) # 200 kB
max_page_diff_block_lines = defaultint(2 ** 7) # 128 lines
max_text_report_size = 0
......@@ -57,7 +67,11 @@ class Config(object):
va = getattr(self, a)
vb = getattr(self, b)
if va < vb:
raise ValueError("{0} ({1}) cannot be smaller than {2} ({3})".format(a, va, b, vb))
if isinstance(vb, defaultint):
logger.warn("%s (%s) < default value of %s (%s), setting latter to %s", a, va, b, vb, va)
setattr(self, b, va)
else:
raise ValueError("{0} ({1}) cannot be smaller than {2} ({3})".format(a, va, b, vb))
def check_constraints(self):
self.check_ge("max_diff_block_lines", "max_page_diff_block_lines")
......
......@@ -146,13 +146,15 @@ def create_parser():
group2.add_argument('--max-page-size', metavar='BYTES', type=int,
help='Maximum bytes of the top-level (--html-dir) or sole '
'(--html) page. (default: %(default)s, remains in effect '
'even with --no-default-limits)',
default=Config().max_page_size).completer=RangeCompleter(Config().max_page_size)
'even with --no-default-limits)', default=
Config().max_page_size).completer=RangeCompleter(
Config().max_page_size)
group2.add_argument('--max-page-size-child', metavar='BYTES', type=int,
help='In --html-dir output, this is the maximum bytes of '
'each child page (default: %(default)s, remains in '
'effect even with --no-default-limits)',
default=Config().max_page_size_child).completer=RangeCompleter(Config().max_page_size_child)
'effect even with --no-default-limits)', default=str(
Config().max_page_size_child)).completer=RangeCompleter(
Config().max_page_size_child)
# TODO: old flag kept for backwards-compat, drop 6 months after v84
group2.add_argument('--max-report-size-child', metavar='BYTES', type=int,
help=argparse.SUPPRESS, default=None)
......@@ -162,8 +164,9 @@ def create_parser():
'spilling it into child pages (--html-dir) or skipping the '
'rest of the diff block. Child pages are limited instead by '
'--max-page-size-child. (default: %(default)s, remains in '
'effect even with --no-default-limits)',
default=Config().max_page_diff_block_lines).completer=RangeCompleter(Config().max_page_diff_block_lines)
'effect even with --no-default-limits)', default=
Config().max_page_diff_block_lines).completer=RangeCompleter(
Config().max_page_diff_block_lines)
# TODO: old flag kept for backwards-compat, drop 6 months after v84
group2.add_argument("--max-diff-block-lines-parent", metavar='LINES', type=int,
help=argparse.SUPPRESS, default=None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment