[Reproducible-commits] [diffoscope] 05/06: Always compare container content if applicable

Jérémy Bobbio lunar at moszumanska.debian.org
Sat Dec 5 23:18:58 UTC 2015


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

lunar pushed a commit to branch master
in repository diffoscope.

commit af6a0f093c2e38a59fe33b31bac345a155f3cfdb
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sat Dec 5 14:08:01 2015 +0000

    Always compare container content if applicable
    
    Now that we have a common interface for containers, we can compare their
    content as part of the default procedure. This saves having to do so
    in every compare_details() methods.
---
 diffoscope/comparators/binary.py   | 12 ++++++++----
 diffoscope/comparators/bzip2.py    |  3 ---
 diffoscope/comparators/cbfs.py     |  5 +----
 diffoscope/comparators/cpio.py     |  6 +-----
 diffoscope/comparators/deb.py      | 11 ++---------
 diffoscope/comparators/debian.py   |  2 --
 diffoscope/comparators/dex.py      |  3 ---
 diffoscope/comparators/elf.py      |  8 +++-----
 diffoscope/comparators/gzip.py     |  6 +-----
 diffoscope/comparators/iso9660.py  |  1 -
 diffoscope/comparators/pdf.py      |  6 ++----
 diffoscope/comparators/rpm.py      |  5 +----
 diffoscope/comparators/squashfs.py |  7 ++-----
 diffoscope/comparators/tar.py      |  5 +----
 diffoscope/comparators/xz.py       |  3 ---
 diffoscope/comparators/zip.py      |  6 +-----
 16 files changed, 23 insertions(+), 66 deletions(-)

diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 583ad67..733f1ba 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -115,7 +115,7 @@ class File(object, metaclass=ABCMeta):
         if not hasattr(self.__class__, 'CONTAINER_CLASS'):
             if hasattr(self, '_other_file'):
                 return self._other_file.__class__.CONTAINER_CLASS(self)
-            raise NotImplemented('Not a container.')
+            return None
         if not hasattr(self, '_as_container'):
             logger.debug('instanciating %s for %s', self.__class__.CONTAINER_CLASS, self)
             self._as_container = self.__class__.CONTAINER_CLASS(self)
@@ -160,8 +160,12 @@ class File(object, metaclass=ABCMeta):
         return compare_binary_files(self, other, source)
 
     def _compare_using_details(self, other, source):
-        details = [d for d in self.compare_details(other, source) if d is not None]
-        if len(details) == 0:
+        details = []
+        if hasattr(self, 'compare_details'):
+            details.extend(filter(None, self.compare_details(other, source)))
+        if self.as_container:
+            details.extend(filter(None, self.as_container.compare(other.as_container)))
+        if not details:
             return None
         difference = Difference(None, self.name, other.name, source=source)
         difference.add_details(details)
@@ -183,7 +187,7 @@ class File(object, metaclass=ABCMeta):
 
     # To be specialized directly, or by implementing compare_details
     def compare(self, other, source=None):
-        if hasattr(self, 'compare_details'):
+        if hasattr(self, 'compare_details') or self.as_container:
             try:
                 difference = self._compare_using_details(other, source)
                 # no differences detected inside? let's at least do a binary diff
diff --git a/diffoscope/comparators/bzip2.py b/diffoscope/comparators/bzip2.py
index 6429847..ff63ef1 100644
--- a/diffoscope/comparators/bzip2.py
+++ b/diffoscope/comparators/bzip2.py
@@ -57,6 +57,3 @@ class Bzip2File(File):
     @staticmethod
     def recognizes(file):
         return Bzip2File.RE_FILE_TYPE.match(file.magic_file_type)
-
-    def compare_details(self, other, source=None):
-        return self.as_container.compare(other.as_container)
diff --git a/diffoscope/comparators/cbfs.py b/diffoscope/comparators/cbfs.py
index a24230c..aa9bfb2 100644
--- a/diffoscope/comparators/cbfs.py
+++ b/diffoscope/comparators/cbfs.py
@@ -129,7 +129,4 @@ class CbfsFile(File):
             return False
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_command(CbfsListing, self.path, other.path))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_command(CbfsListing, self.path, other.path)]
diff --git a/diffoscope/comparators/cpio.py b/diffoscope/comparators/cpio.py
index 536e80c..9c235b3 100644
--- a/diffoscope/comparators/cpio.py
+++ b/diffoscope/comparators/cpio.py
@@ -41,8 +41,4 @@ class CpioFile(File):
         return CpioFile.RE_FILE_TYPE.search(file.magic_file_type)
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_command(
-            CpioContent, self.path, other.path, source="file list"))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_command(CpioContent, self.path, other.path, source="file list")]
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 8043389..3851323 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -51,13 +51,9 @@ class DebFile(File):
         self._files_with_same_content_in_data = files
 
     def compare_details(self, other, source=None):
-        differences = []
         my_content = get_ar_content(self.path)
         other_content = get_ar_content(other.path)
-        differences.append(Difference.from_text(
-                               my_content, other_content, self.path, other.path, source="metadata"))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_text(my_content, other_content, self.path, other.path, source="metadata")]
 
 
 class Md5sumsFile(File):
@@ -123,7 +119,4 @@ class DebDataTarFile(File):
                isinstance(file.container.source.container.source, DebFile)
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_command(TarListing, self.path, other.path))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_command(TarListing, self.path, other.path)]
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index 703804d..14a3480 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -122,8 +122,6 @@ class DebControlFile(File):
         differences.append(Difference.from_text(self.deb822.get_as_string('Files'),
                                                 other.deb822.get_as_string('Files'),
                                                 self.path, other.path, source='Files'))
-        differences.extend(self.as_container.compare(other.as_container))
-
         return differences
 
 class DotChangesFile(DebControlFile):
diff --git a/diffoscope/comparators/dex.py b/diffoscope/comparators/dex.py
index 017f1d4..9ad4cb5 100644
--- a/diffoscope/comparators/dex.py
+++ b/diffoscope/comparators/dex.py
@@ -58,6 +58,3 @@ class DexFile(File):
     @staticmethod
     def recognizes(file):
         return DexFile.RE_FILE_TYPE.match(file.magic_file_type)
-
-    def compare_details(self, other, source=None):
-        return self.as_container.compare(other.as_container)
diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index 30f6953..0aa6386 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -77,11 +77,9 @@ class ObjdumpDisassemble(Command):
             return line
 
 def _compare_elf_data(path1, path2):
-    differences = []
-    differences.append(Difference.from_command(ReadelfAll, path1, path2))
-    differences.append(Difference.from_command(ReadelfDebugDump, path1, path2))
-    differences.append(Difference.from_command(ObjdumpDisassemble, path1, path2))
-    return differences
+    return [Difference.from_command(ReadelfAll, path1, path2),
+            Difference.from_command(ReadelfDebugDump, path1, path2),
+            Difference.from_command(ObjdumpDisassemble, path1, path2)]
 
 class ElfFile(File):
     RE_FILE_TYE = re.compile(r'^ELF ')
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index f9f585b..a8b19c8 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -59,8 +59,4 @@ class GzipFile(object):
         return GzipFile.RE_FILE_TYPE.match(file.magic_file_type)
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_text(
-                               self.magic_file_type, other.magic_file_type, self, other, source='metadata'))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')]
diff --git a/diffoscope/comparators/iso9660.py b/diffoscope/comparators/iso9660.py
index f194fef..4cdd0d3 100644
--- a/diffoscope/comparators/iso9660.py
+++ b/diffoscope/comparators/iso9660.py
@@ -78,5 +78,4 @@ class Iso9660File(File):
                 differences.append(Difference.from_command(ISO9660Listing, self.path, other.path, command_args=(extension,)))
             except subprocess.CalledProcessError:
                 pass # probably no joliet or rockridge data
-        differences.extend(self.as_container.compare(other.as_container))
         return differences
diff --git a/diffoscope/comparators/pdf.py b/diffoscope/comparators/pdf.py
index d105c07..7df3ff0 100644
--- a/diffoscope/comparators/pdf.py
+++ b/diffoscope/comparators/pdf.py
@@ -47,7 +47,5 @@ class PdfFile(File):
         return PdfFile.RE_FILE_TYPE.match(file.magic_file_type)
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_command(Pdftotext, self.path, other.path))
-        differences.append(Difference.from_command(Pdftk, self.path, other.path))
-        return differences
+        return [Difference.from_command(Pdftotext, self.path, other.path),
+                Difference.from_command(Pdftk, self.path, other.path)]
diff --git a/diffoscope/comparators/rpm.py b/diffoscope/comparators/rpm.py
index bf4ee4c..0bdde1f 100644
--- a/diffoscope/comparators/rpm.py
+++ b/diffoscope/comparators/rpm.py
@@ -100,7 +100,4 @@ class RpmFile(AbstractRpmFile):
     CONTAINER_CLASS = RpmContainer
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(compare_rpm_headers(self.path, other.path))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [compare_rpm_headers(self.path, other.path)]
diff --git a/diffoscope/comparators/squashfs.py b/diffoscope/comparators/squashfs.py
index b2b5b2f..2531d99 100644
--- a/diffoscope/comparators/squashfs.py
+++ b/diffoscope/comparators/squashfs.py
@@ -196,8 +196,5 @@ class SquashfsFile(File):
         return SquashfsFile.RE_FILE_TYPE.match(file.magic_file_type)
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_command(SquashfsSuperblock, self.path, other.path))
-        differences.append(Difference.from_command(SquashfsListing, self.path, other.path))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_command(SquashfsSuperblock, self.path, other.path),
+                Difference.from_command(SquashfsListing, self.path, other.path)]
diff --git a/diffoscope/comparators/tar.py b/diffoscope/comparators/tar.py
index a876bec..0739817 100644
--- a/diffoscope/comparators/tar.py
+++ b/diffoscope/comparators/tar.py
@@ -41,7 +41,4 @@ class TarFile(File):
         return TarFile.RE_FILE_TYPE.search(file.magic_file_type)
 
     def compare_details(self, other, source=None):
-        differences = []
-        differences.append(Difference.from_command(TarListing, self.path, other.path))
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [Difference.from_command(TarListing, self.path, other.path)]
diff --git a/diffoscope/comparators/xz.py b/diffoscope/comparators/xz.py
index 98dc81d..79418f8 100644
--- a/diffoscope/comparators/xz.py
+++ b/diffoscope/comparators/xz.py
@@ -57,6 +57,3 @@ class XzFile(File):
     @staticmethod
     def recognizes(file):
         return XzFile.RE_FILE_TYPE.match(file.magic_file_type)
-
-    def compare_details(self, other, source=None):
-        return self.as_container.compare(other.as_container)
diff --git a/diffoscope/comparators/zip.py b/diffoscope/comparators/zip.py
index 103cbf3..ecdc77b 100644
--- a/diffoscope/comparators/zip.py
+++ b/diffoscope/comparators/zip.py
@@ -108,10 +108,6 @@ class ZipFile(File):
         return ZipFile.RE_FILE_TYPE.match(file.magic_file_type)
 
     def compare_details(self, other, source=None):
-        differences = []
-        # look up differences in metadata
         zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
                              Difference.from_command(ZipinfoVerbose, self.path, other.path)
-        differences.append(zipinfo_difference)
-        differences.extend(self.as_container.compare(other.as_container))
-        return differences
+        return [zipinfo_difference]

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



More information about the Reproducible-commits mailing list