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

Ximin Luo infinity0 at debian.org
Fri Sep 22 14:09:07 CEST 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository diffoscope.

commit 510162b7e4539f41690b55a3c8697f8d640d4f31
Author: Ximin Luo <infinity0 at debian.org>
Date:   Fri Sep 22 14:08:14 2017 +0200

    config: force-set a value if it must be < another, and it was not set on purpose (Closes: #875451)
---
 diffoscope/config.py | 26 ++++++++++++++++++++------
 diffoscope/main.py   | 15 +++++++++------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/diffoscope/config.py b/diffoscope/config.py
index d6e6f84..fbc2acb 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -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")
diff --git a/diffoscope/main.py b/diffoscope/main.py
index f6ccbe2..4868758 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -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)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list