[diffoscope] 01/01: presenters/formats: allow non-text formats to output an empty diff

Ximin Luo infinity0 at debian.org
Sat Dec 2 16:54:35 CET 2017


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

infinity0 pushed a commit to branch master
in repository diffoscope.

commit 0670bc0b14f0630d3307d31d4dcd1e467eb0133f
Author: Ximin Luo <infinity0 at debian.org>
Date:   Sat Dec 2 16:44:23 2017 +0100

    presenters/formats: allow non-text formats to output an empty diff
---
 diffoscope/presenters/formats.py | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/diffoscope/presenters/formats.py b/diffoscope/presenters/formats.py
index 0f537e0..24b7190 100644
--- a/diffoscope/presenters/formats.py
+++ b/diffoscope/presenters/formats.py
@@ -85,23 +85,21 @@ 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'])
 
+            # As a special case for text format, write an empty file instead of
+            # an empty diff (with headers including the path). This lets people
+            # test if the file is empty.
+            if not has_differences and name == 'text':
+                target = data['target']
+                if target != '-':
+                    open(target, 'w').close()
+                continue
+
             with profile('output', name):
                 data['klass'].run(data, difference, parsed_args)
 

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


More information about the diffoscope mailing list