[diffoscope] 05/05: Drop passing has_differences around, fixing an issue with generating files called '-'

Chris Lamb chris at chris-lamb.co.uk
Sun Apr 30 11:02:26 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 32ff05e050829052bc9745645a3b74ead947adb5
Author: Chris Lamb <lamby at debian.org>
Date:   Sun Apr 30 10:01:06 2017 +0100

    Drop passing has_differences around, fixing an issue with generating files called '-'
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/presenters/formats.py   | 23 ++++++++++++++++-------
 diffoscope/presenters/html/html.py |  4 ++--
 diffoscope/presenters/text.py      |  9 ++-------
 diffoscope/presenters/utils.py     |  2 +-
 4 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/diffoscope/presenters/formats.py b/diffoscope/presenters/formats.py
index 94b723f..0f537e0 100644
--- a/diffoscope/presenters/formats.py
+++ b/diffoscope/presenters/formats.py
@@ -76,7 +76,7 @@ class PresenterManager(object):
 
         # If no output specified, default to printing --text output to stdout
         if not self.config:
-            parsed_args.text_output = FORMATS['text']['target'] = '-'
+            FORMATS['text']['target'] = '-'
             self.config['text'] = FORMATS['text']
 
         logger.debug(
@@ -85,16 +85,25 @@ class PresenterManager(object):
         )
 
     def output(self, difference, parsed_args, has_differences):
+        # As a special case, write an empty file instead of an empty diff.
+        if not has_differences:
+            try:
+                target = self.config['text']['target']
+
+                if target != '-':
+                    open(target, 'w').close()
+            except KeyError:
+                pass
+            return
+
+        if difference is None:
+            return
+
         for name, data in self.config.items():
             logger.debug("Generating %r output at %r", name, data['target'])
 
             with profile('output', name):
-                data['klass'].run(
-                    data,
-                    difference,
-                    parsed_args,
-                    has_differences,
-                )
+                data['klass'].run(data, difference, parsed_args)
 
     def compute_visual_diffs(self):
         """
diff --git a/diffoscope/presenters/html/html.py b/diffoscope/presenters/html/html.py
index 9a86261..cf41b09 100644
--- a/diffoscope/presenters/html/html.py
+++ b/diffoscope/presenters/html/html.py
@@ -82,7 +82,7 @@ class HTMLPresenter(Presenter):
     supports_visual_diffs = True
 
     @classmethod
-    def run(cls, data, difference, parsed_args, has_differences):
+    def run(cls, data, difference, parsed_args):
         with make_printer(parsed_args.html_output) as fn:
             output_html(
                 difference,
@@ -93,7 +93,7 @@ class HTMLPresenter(Presenter):
 
 class HTMLDirectoryPresenter(HTMLPresenter):
     @classmethod
-    def run(cls, data, difference, parsed_args, has_differences):
+    def run(cls, data, difference, parsed_args):
         output_html_directory(
             parsed_args.html_output_directory,
             difference,
diff --git a/diffoscope/presenters/text.py b/diffoscope/presenters/text.py
index 842d0ff..7a16385 100644
--- a/diffoscope/presenters/text.py
+++ b/diffoscope/presenters/text.py
@@ -44,13 +44,8 @@ class TextPresenter(Presenter):
         super().__init__()
 
     @classmethod
-    def run(cls, data, difference, parsed_args, has_differences):
-        # As a special case, write an empty file instead of an empty diff.
-        if not has_differences:
-            open(parsed_args.text_output, 'w').close()
-            return
-
-        with make_printer(parsed_args.text_output or '-') as fn:
+    def run(cls, data, difference, parsed_args):
+        with make_printer(data['target']) as fn:
             color = {
                 'auto': fn.output.isatty(),
                 'never': False,
diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index 74da0f4..188352e 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -29,7 +29,7 @@ class Presenter(object):
         self.depth = 0
 
     @classmethod
-    def run(cls, data, difference, parsed_args, has_differences):
+    def run(cls, data, difference, parsed_args):
         with make_printer(data['target']) as fn:
             cls(fn).start(difference)
 

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


More information about the diffoscope mailing list