[diffoscope] 02/03: Add a Difference.from_command_exc to distinguish excluded commands from empty diff

Ximin Luo infinity0 at debian.org
Tue Nov 28 19:24:02 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 f1486154191c27e1c80547b5c93993ec78882e45
Author: Ximin Luo <infinity0 at debian.org>
Date:   Tue Nov 28 19:20:09 2017 +0100

    Add a Difference.from_command_exc to distinguish excluded commands from empty diff
---
 diffoscope/comparators/elf.py | 12 +++++++++---
 diffoscope/difference.py      | 19 ++++++++++++-------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index c572601..181ea6e 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -336,17 +336,23 @@ class ElfCodeSection(ElfSection):
         # Normally disassemble with line numbers, but if the command is
         # excluded, fallback to disassembly, and if that is also excluded,
         # fallback to a hexdump.
-        return Difference.from_command(
+        diff, excluded = Difference.from_command_exc(
             ObjdumpDisassembleSection,
             self.path,
             other.path,
             command_args=[self._name],
-        ) or Difference.from_command(
+        )
+        if not excluded:
+            return diff
+        diff, excluded = Difference.from_command_exc(
             ObjdumpDisassembleSectionNoLineNumbers,
             self.path,
             other.path,
             command_args=[self._name],
-        ) or super().compare(other, source)
+        )
+        if not excluded:
+            return diff
+        return super().compare(other, source)
 
 
 class ElfStringSection(ElfSection):
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index 88c6244..be4af7c 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -226,6 +226,10 @@ class Difference(object):
 
     @staticmethod
     def from_command(klass, path1, path2, *args, **kwargs):
+        return Difference.from_command_exc(klass, path1, path2, *args, **kwargs)[0]
+
+    @staticmethod
+    def from_command_exc(klass, path1, path2, *args, **kwargs):
         command_args = []
         if 'command_args' in kwargs:
             command_args = kwargs['command_args']
@@ -239,14 +243,15 @@ class Difference(object):
                 command = klass(path, *command_args)
                 feeder = feeders.from_command(command)
                 if command_excluded(command.shell_cmdline()):
-                    return None, None
+                    return None, None, True
                 command.start()
-            return feeder, command
+            return feeder, command, False
 
-        feeder1, command1 = command_and_feeder(path1)
-        feeder2, command2 = command_and_feeder(path2)
+        feeder1, command1, excluded1 = command_and_feeder(path1)
+        feeder2, command2, excluded2 = command_and_feeder(path2)
         if not feeder1 or not feeder2:
-            return None
+            assert excluded1 or excluded2
+            return None, True
 
         if 'source' not in kwargs:
             source_cmd = command1 or command2
@@ -261,7 +266,7 @@ class Difference(object):
             **kwargs
         )
         if not difference:
-            return None
+            return None, False
 
         if command1 and command1.stderr_content:
             difference.add_comment("stderr from `{}`:".format(
@@ -274,7 +279,7 @@ class Difference(object):
             ))
             difference.add_comment(command2.stderr_content)
 
-        return difference
+        return difference, False
 
     @property
     def comment(self):

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


More information about the diffoscope mailing list