[diffoscope] 03/03: html-dir: use 4 * the given max-diff-block-lines

Ximin Luo infinity0 at debian.org
Thu Sep 8 16:42:15 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 8a4729c9eb2b14fd3b9bb7cf2b17bffeeae079c9
Author: Ximin Luo <infinity0 at debian.org>
Date:   Thu Sep 8 16:40:33 2016 +0200

    html-dir: use 4 * the given max-diff-block-lines
    
    This way, --html x.html --html-dir x gives reasonable output for both.
    
    The hardcoded ratio could be another flag, but I think we have enough flags.
---
 diffoscope/config.py          | 15 +++++++++++----
 diffoscope/main.py            |  8 +++++---
 diffoscope/presenters/html.py |  3 ++-
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/diffoscope/config.py b/diffoscope/config.py
index 55b7d04..ada80b5 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -27,9 +27,11 @@ class classproperty(property):
 
 class Config(object):
     def __init__(self):
-        self._max_diff_block_lines = 1024
+        self._max_diff_block_lines = 256
         self._max_diff_block_lines_parent = 50
         self._max_diff_block_lines_saved = float("inf")
+        # html-dir output uses ratio * max-diff-block-lines as its limit
+        self._max_diff_block_lines_html_dir_ratio = 4
         self._max_diff_input_lines = 2 ** 20 # GNU diff cannot process arbitrary large files :(
         self._max_report_size = 2000 * 2 ** 10 # 2000 kB
         self._max_report_child_size = 500 * 2 ** 10
@@ -46,9 +48,10 @@ class Config(object):
         if self._max_diff_block_lines < self._max_diff_block_lines_parent:
             raise ValueError("max_diff_block_lines (%s) cannot be smaller than max_diff_block_lines_parent (%s)" %
                 (self._max_diff_block_lines, self._max_diff_block_lines_parent))
-        if self._max_diff_block_lines_saved < self._max_diff_block_lines:
-            raise ValueError("max_diff_block_lines_saved (%s) cannot be smaller than max_diff_block_lines (%s)" %
-                (self._max_diff_block_lines_saved, self._max_diff_block_lines))
+        m = self._max_diff_block_lines_html_dir_ratio
+        if self._max_diff_block_lines_saved < m * self._max_diff_block_lines:
+            raise ValueError("max_diff_block_lines_saved (%s) cannot be smaller than %d*max_diff_block_lines (%s)" %
+                (self._max_diff_block_lines_saved, m, m*self._max_diff_block_lines))
 
     @property
     def max_diff_block_lines(self):
@@ -78,6 +81,10 @@ class Config(object):
         self._check_constraints()
 
     @property
+    def max_diff_block_lines_html_dir_ratio(self):
+        return self._max_diff_block_lines_html_dir_ratio
+
+    @property
     def max_diff_input_lines(self):
         return self._max_diff_input_lines
 
diff --git a/diffoscope/main.py b/diffoscope/main.py
index dc19a15..6ea1bdc 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -86,9 +86,11 @@ def create_parser():
                         Config.general.max_report_child_size, 50000)
     parser.add_argument('--max-diff-block-lines', dest='max_diff_block_lines',
                         metavar='LINES', type=int,
-                        help='Maximum number of lines output per diff block, '
-                        'across the whole report. (0 to disable, default: %d)' %
-                        Config.general.max_diff_block_lines,
+                        help='Maximum number of lines output per diff block. '
+                        'In html-dir output, we use %d * this number instead, '
+                        'taken over all pages. (0 to disable, default: %d)' %
+                        (Config.general.max_diff_block_lines_html_dir_ratio,
+                        Config.general.max_diff_block_lines),
                         default=None).completer=RangeCompleter(0,
                         Config.general.max_diff_block_lines, 5)
     parser.add_argument('--max-diff-block-lines-parent', dest='max_diff_block_lines_parent',
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index fbc0a48..0d83da7 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -495,6 +495,7 @@ def row_was_output():
     _, rotation_params = spl_print_ctrl
     max_lines = Config.general.max_diff_block_lines
     max_lines_parent = Config.general.max_diff_block_lines_parent
+    max_lines_ratio = Config.general.max_diff_block_lines_html_dir_ratio
     max_report_child_size = Config.general.max_report_child_size
     if not rotation_params:
         # html-dir single output, don't need to rotate
@@ -504,7 +505,7 @@ def row_was_output():
     else:
         # html-dir output, perhaps need to rotate
         directory, mainname, css_url = rotation_params
-        if spl_rows >= max_lines:
+        if spl_rows >= max_lines_ratio * max_lines:
             raise DiffBlockLimitReached()
 
         if spl_current_page == 0: # on parent page

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


More information about the diffoscope mailing list