Commits (2)
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2016-2021 Chris Lamb <lamby@debian.org>
# Copyright © 2016-2022 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -434,6 +434,12 @@ class File(metaclass=abc.ABCMeta):
msg = "Reached max container depth ({})".format(depth)
logger.debug(msg)
difference.add_comment(msg)
elif Config().timeout_exceeded():
msg = "Timeout exceeded; details may be incomplete."
logger.debug(msg)
difference.add_comment(msg)
no_recurse = True
details.extend(
self.as_container.compare(
other.as_container, no_recurse=no_recurse
......
......@@ -2,7 +2,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2015 Reiner Herrmann <reiner@reiner-h.de>
# Copyright © 2016-2017, 2019-2021 Chris Lamb <lamby@debian.org>
# Copyright © 2016-2017, 2019-2022 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -19,6 +19,7 @@
import logging
import time
logger = logging.getLogger(__name__)
......@@ -69,6 +70,9 @@ class Config:
self.use_dbgsym = "auto"
self.force_details = False
self.started = time.time()
self.timeout = float("inf")
def __setattr__(self, k, v):
super(Config, self).__setattr__(k, v)
......@@ -76,23 +80,26 @@ class Config:
va = getattr(self, a)
vb = getattr(self, b)
if va < vb:
if isinstance(vb, defaultint):
logger.warning(
"%s (%s) < default value of %s (%s), setting latter to %s",
a,
va,
b,
vb,
va,
)
setattr(self, b, va)
else:
if not isinstance(vb, defaultint):
raise ValueError(
"{0} ({1}) cannot be smaller than {2} ({3})".format(
a, va, b, vb
)
)
logger.warning(
"%s (%s) < default value of %s (%s), setting latter to %s",
a,
va,
b,
vb,
va,
)
setattr(self, b, va)
def check_constraints(self):
self.check_ge("max_diff_block_lines", "max_page_diff_block_lines")
self.check_ge("max_report_size", "max_page_size")
def timeout_exceeded(self):
return (self.started + self.timeout) < time.time()
......@@ -4,7 +4,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2014-2015 Jérémy Bobbio <lunar@debian.org>
# Copyright © 2016-2021 Chris Lamb <lamby@debian.org>
# Copyright © 2016-2022 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -366,6 +366,13 @@ def create_parser():
"%(default)s)",
default=Config().max_container_depth,
)
group3.add_argument(
"--timeout",
metavar="SECONDS",
type=int,
help="Best-effort attempt at a timeout in seconds. (default: no timeout) [experimental]",
default=float("inf"),
)
group3.add_argument(
"--max-diff-block-lines-saved",
metavar="LINES",
......@@ -628,6 +635,7 @@ def configure(parsed_args):
Config().use_dbgsym = parsed_args.use_dbgsym
Config().force_details = parsed_args.force_details
Config().fuzzy_threshold = parsed_args.fuzzy_threshold
Config().timeout = parsed_args.timeout
Config().max_container_depth = parsed_args.max_container_depth
Config().excludes = parsed_args.excludes
......