[diffoscope] 01/01: Add a --no-max flag to disable all limits and have max_report_size also honour 0 to mean "no limit"

Ximin Luo infinity0 at debian.org
Wed Aug 24 17:43:06 CEST 2016


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

infinity0 pushed a commit to branch master
in repository diffoscope.

commit a095c624ad795cf9e316ed3ae7d8eb5e5d01ab39
Author: Ximin Luo <infinity0 at debian.org>
Date:   Wed Aug 24 17:41:30 2016 +0200

    Add a --no-max flag to disable all limits and have max_report_size also honour 0 to mean "no limit"
---
 diffoscope/config.py          |  1 +
 diffoscope/main.py            | 31 ++++++++++++++++++++-----------
 diffoscope/presenters/html.py |  2 +-
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/diffoscope/config.py b/diffoscope/config.py
index ff65558..b99dc72 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -27,6 +27,7 @@ class classproperty(property):
 
 class Config(object):
     def __init__(self):
+        # 0 to disable max
         self._max_diff_block_lines = 50
         self._max_diff_input_lines = 100000 # GNU diff cannot process arbitrary large files :(
         self._max_report_size = 2000 * 2 ** 10 # 2000 kB
diff --git a/diffoscope/main.py b/diffoscope/main.py
index b54c44c..1a65b65 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -66,27 +66,28 @@ def create_parser():
                         help='write multi-file HTML report to given directory')
     parser.add_argument('--text', metavar='output', dest='text_output',
                         help='write plain text output to given file (use - for stdout)')
+    parser.add_argument('--no-max-limits', action='store_true', default=False,
+                        help='Disable all default limits.')
     parser.add_argument('--max-report-size', metavar='BYTES',
                         dest='max_report_size', type=int,
-                        help='maximum bytes written in report (default: %d)' %
+                        help='maximum bytes written in report (default: %d, 0 to disable)' %
                         Config.general.max_report_size,
-                        default=Config.general.max_report_size).completer=RangeCompleter(0,
+                        default=None).completer=RangeCompleter(0,
                         Config.general.max_report_size, 200000)
     parser.add_argument('--separate-file-diff-size', metavar='BYTES',
                         dest='separate_file_diff_size', type=int,
-                        help='diff size to load diff on demand, with --html-dir (default: %d)' %
-                        Config.general.separate_file_diff_size,
+                        help='diff size to load diff on demand, with --html-dir (default: %(default)s)',
                         default=Config.general.separate_file_diff_size).completer=RangeCompleter(0,
                         Config.general.separate_file_diff_size, 20000)
     parser.add_argument('--max-diff-block-lines', dest='max_diff_block_lines', type=int,
-                        help='maximum number of lines per diff block (default: %d)' %
+                        help='maximum number of lines per diff block (default: %d, 0 to disable)' %
                         Config.general.max_diff_block_lines,
-                        default=Config.general.max_diff_block_lines).completer=RangeCompleter(0,
+                        default=None).completer=RangeCompleter(0,
                         Config.general.max_diff_block_lines, 5)
     parser.add_argument('--max-diff-input-lines', dest='max_diff_input_lines', type=int,
-                        help='maximum number of lines fed to diff (default: %d)' %
+                        help='maximum number of lines fed to diff (default: %d, 0 to disable)' %
                         Config.general.max_diff_input_lines,
-                        default=Config.general.max_diff_input_lines).completer=RangeCompleter(0,
+                        default=None).completer=RangeCompleter(0,
                         Config.general.max_diff_input_lines, 5000)
     parser.add_argument('--fuzzy-threshold', dest='fuzzy_threshold', type=int,
                         help='threshold for fuzzy-matching '
@@ -161,13 +162,21 @@ class ListToolsAction(argparse.Action):
         sys.exit(0)
 
 
+def maybe_set_limit(config, parsed_args, key):
+    v = getattr(parsed_args, key)
+    if v is not None:
+        setattr(config, key, v)
+    elif parsed_args.no_max_limits:
+        setattr(config, key, 0)
+
+
 def run_diffoscope(parsed_args):
     if not tlsh and Config.general.fuzzy_threshold != parsed_args.fuzzy_threshold:
         logger.warning('Fuzzy-matching is currently disabled as the “tlsh” module is unavailable.')
-    Config.general.max_diff_block_lines = parsed_args.max_diff_block_lines
-    Config.general.max_diff_input_lines = parsed_args.max_diff_input_lines
-    Config.general.max_report_size = parsed_args.max_report_size
+    maybe_set_limit(Config.general, parsed_args, "max_report_size")
     Config.general.separate_file_diff_size = parsed_args.separate_file_diff_size
+    maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines")
+    maybe_set_limit(Config.general, parsed_args, "max_diff_input_lines")
     Config.general.fuzzy_threshold = parsed_args.fuzzy_threshold
     Config.general.new_file = parsed_args.new_file
     if parsed_args.debug:
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 13b2550..be8b145 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -192,7 +192,7 @@ def create_limited_print_func(print_func, max_page_size):
             limited_print_func.char_count = 0
         print_func(s)
         limited_print_func.char_count += len(s)
-        if not force and limited_print_func.char_count >= max_page_size:
+        if not force and max_page_size > 0 and limited_print_func.char_count >= max_page_size:
             raise PrintLimitReached()
     return limited_print_func
 

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


More information about the diffoscope mailing list