[diffoscope] 03/03: Document the 'h' variable in our raw_feeder

Chris Lamb chris at chris-lamb.co.uk
Fri Jun 16 07:07:39 CEST 2017


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

lamby pushed a commit to branch experimental
in repository diffoscope.

commit ad28ed35a8303fb6c37fc76805c56339bc5b1c3f
Author: Chris Lamb <lamby at debian.org>
Date:   Fri Jun 16 12:42:06 2017 +0800

    Document the 'h' variable in our raw_feeder
---
 diffoscope/feeders.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/diffoscope/feeders.py b/diffoscope/feeders.py
index ac1b2ce..b285ee6 100644
--- a/diffoscope/feeders.py
+++ b/diffoscope/feeders.py
@@ -33,24 +33,32 @@ DIFF_CHUNK = 4096
 def from_raw_reader(in_file, filter=lambda buf: buf):
     def feeder(out_file):
         max_lines = Config().max_diff_input_lines
-        line_count = 0
         end_nl = False
+        line_count = 0
+
+        # If we have a maximum size, hash the content as we go along so we can
+        # display a nicer message.
         h = None
         if max_lines < float('inf'):
             h = hashlib.sha1()
+
         for buf in in_file:
             line_count += 1
             out = filter(buf)
-            if h:
+
+            if h is not None:
                 h.update(out)
+
             if line_count < max_lines:
                 out_file.write(out)
             end_nl = buf[-1] == '\n'
-        if h and line_count >= max_lines:
+
+        if h is not None and line_count >= max_lines:
             out_file.write("[ Too much input for diff (SHA1: {}) ]\n".format(
                 h.hexdigest(),
             ).encode('utf-8'))
             end_nl = True
+
         return end_nl
     return feeder
 

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


More information about the diffoscope mailing list