[diffoscope] 02/03: Set limits to inf when parsing args, instead of checking for "> 0" everywhere

Ximin Luo infinity0 at debian.org
Tue Sep 6 22:58:32 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 b43a3a588c6271d6698c425e78b095f5f3b3e72e
Author: Ximin Luo <infinity0 at debian.org>
Date:   Tue Sep 6 21:24:49 2016 +0200

    Set limits to inf when parsing args, instead of checking for "> 0" everywhere
---
 diffoscope/difference.py      | 6 +++---
 diffoscope/main.py            | 4 ++--
 diffoscope/presenters/html.py | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index edffc72..53faffc 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -110,7 +110,7 @@ class DiffParser(object):
         if line[0] in ('-', '+') and line[0] == self._direction:
             self._block_len += 1
             max_lines = Config.general.max_diff_block_lines
-            if max_lines > 0 and self._block_len >= max_lines:
+            if self._block_len >= max_lines:
                 return self.skip_block
         else:
             self._block_len = 1
@@ -229,14 +229,14 @@ def make_feeder_from_raw_reader(in_file, filter=lambda buf: buf):
         line_count = 0
         end_nl = False
         h = None
-        if max_lines > 0:
+        if max_lines < float("inf"):
             h = hashlib.sha1()
         for buf in in_file:
             line_count += 1
             out = filter(buf)
             if h:
                 h.update(out)
-            if max_lines == 0 or line_count < max_lines:
+            if line_count < max_lines:
                 out_file.write(out)
             end_nl = buf[-1] == '\n'
         if h and line_count >= max_lines:
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 1a65b65..4de7e7f 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -165,9 +165,9 @@ class ListToolsAction(argparse.Action):
 def maybe_set_limit(config, parsed_args, key):
     v = getattr(parsed_args, key)
     if v is not None:
-        setattr(config, key, v)
+        setattr(config, key, float("inf") if v == 0 else v)
     elif parsed_args.no_max_limits:
-        setattr(config, key, 0)
+        setattr(config, key, float("inf"))
 
 
 def run_diffoscope(parsed_args):
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 329e71f..2c1f1d6 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -190,7 +190,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 max_page_size > 0 and limited_print_func.char_count >= max_page_size:
+        if not force 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