[diffoscope] 01/03: When enforcing max-container-depth, show which internal files differ, without showing details

Ximin Luo infinity0 at debian.org
Wed May 24 19:23:29 CEST 2017


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

infinity0 pushed a commit to branch experimental
in repository diffoscope.

commit b1cec94ac2ff7534e0c155c239131897d7490f0a
Author: Ximin Luo <infinity0 at debian.org>
Date:   Wed May 24 18:33:57 2017 +0200

    When enforcing max-container-depth, show which internal files differ, without showing details
---
 diffoscope/comparators/apk.py             |  4 ++--
 diffoscope/comparators/debian.py          |  4 ++--
 diffoscope/comparators/debian_fallback.py | 12 ++++++------
 diffoscope/comparators/directory.py       |  2 +-
 diffoscope/comparators/ps.py              |  4 ++--
 diffoscope/comparators/utils/compare.py   | 10 +++++++---
 diffoscope/comparators/utils/container.py | 15 +++++++++------
 diffoscope/comparators/utils/file.py      |  7 +++----
 tests/comparators/test_deb.py             |  4 ++--
 9 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/diffoscope/comparators/apk.py b/diffoscope/comparators/apk.py
index cd3ef21..8263624 100644
--- a/diffoscope/comparators/apk.py
+++ b/diffoscope/comparators/apk.py
@@ -136,13 +136,13 @@ class ApkContainer(Archive):
             diff_manifests.add_comment(comment)
         return diff_manifests
 
-    def compare(self, other, source=None):
+    def compare(self, other, **kwargs):
         differences = []
         try:
             differences.append(self.compare_manifests(other))
         except AttributeError:  # no apk-specific methods, e.g. MissingArchive
             pass
-        differences.extend(super().compare(other, source=source))
+        differences.extend(super().compare(other, **kwargs))
         return differences
 
 class ApkFile(File):
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index dc182db..4658fc2 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -181,8 +181,8 @@ class DotChangesFile(DebControlFile):
 
         return True
 
-    def compare(self, other, source=None):
-        differences = super().compare(other, source)
+    def compare(self, other, **kwargs):
+        differences = super().compare(other, **kwargs)
 
         if differences is None:
             return None
diff --git a/diffoscope/comparators/debian_fallback.py b/diffoscope/comparators/debian_fallback.py
index a52f133..90858b1 100644
--- a/diffoscope/comparators/debian_fallback.py
+++ b/diffoscope/comparators/debian_fallback.py
@@ -25,8 +25,8 @@ from .text import TextFile
 class DotChangesFile(TextFile):
     RE_FILE_EXTENSION = re.compile(r'\.changes$')
 
-    def compare(self, other, source=None):
-        difference = super().compare(other)
+    def compare(self, other, **kwargs):
+        difference = super().compare(other, **kwargs)
         if not difference:
             return None
         difference.add_comment('Unable to find Python debian module. Falling back to text comparison.')
@@ -35,8 +35,8 @@ class DotChangesFile(TextFile):
 class DotDscFile(TextFile):
     RE_FILE_EXTENSION = re.compile(r'\.dsc$')
 
-    def compare(self, other, source=None):
-        difference = super().compare(other)
+    def compare(self, other, **kwargs):
+        difference = super().compare(other, **kwargs)
         if not difference:
             return None
         difference.add_comment('Unable to find Python debian module. Falling back to text comparison.')
@@ -45,8 +45,8 @@ class DotDscFile(TextFile):
 class DotBuildinfoFile(TextFile):
     RE_FILE_EXTENSION = re.compile(r'\.buildinfo$')
 
-    def compare(self, other, source=None):
-        difference = super().compare(other)
+    def compare(self, other, **kwargs):
+        difference = super().compare(other, **kwargs)
         if not difference:
             return None
         difference.add_comment('Unable to find Python debian module. Falling back to text comparison.')
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index 1327912..c3e8a70 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -131,7 +131,7 @@ class Directory(object):
         return file.is_directory()
 
 
-class FilesystemDirectory(object):
+class FilesystemDirectory(Directory):
     def __init__(self, path):
         self._path = path
 
diff --git a/diffoscope/comparators/ps.py b/diffoscope/comparators/ps.py
index a7e1a40..ea94b9e 100644
--- a/diffoscope/comparators/ps.py
+++ b/diffoscope/comparators/ps.py
@@ -39,8 +39,8 @@ class Pstotext(Command):
 class PsFile(TextFile):
     RE_FILE_TYPE = re.compile(r'^PostScript document\b')
 
-    def compare(self, other, source=None):
-        differences = super().compare(other, source)
+    def compare(self, other, **kwargs):
+        differences = super().compare(other, **kwargs)
         details = None
         try:
             details = Difference.from_command(Pstotext, self.path, other.path)
diff --git a/diffoscope/comparators/utils/compare.py b/diffoscope/comparators/utils/compare.py
index 4259409..a114a20 100644
--- a/diffoscope/comparators/utils/compare.py
+++ b/diffoscope/comparators/utils/compare.py
@@ -63,7 +63,7 @@ def compare_root_paths(path1, path2):
     file2 = specialize(FilesystemFile(path2, container=container2))
     return compare_files(file1, file2)
 
-def compare_files(file1, file2, source=None):
+def compare_files(file1, file2, source=None, diff_content_only=False):
     logger.debug(
         "Comparing %s (%s) and %s (%s)",
         file1.name,
@@ -79,6 +79,10 @@ def compare_files(file1, file2, source=None):
         if file1.has_same_content_as(file2):
             logger.debug("has_same_content_as returned True; skipping further comparisons")
             return None
+    if diff_content_only:
+        difference = Difference(None, file1.name, file2.name)
+        difference.add_comment("Files differ")
+        return difference
     specialize(file1)
     specialize(file2)
     if isinstance(file1, MissingFile):
@@ -90,8 +94,8 @@ def compare_files(file1, file2, source=None):
     with profile('compare_files (cumulative)', file1):
         return file1.compare(file2, source)
 
-def compare_commented_files(file1, file2, comment=None, source=None):
-    difference = compare_files(file1, file2, source=source)
+def compare_commented_files(diff_content_only, file1, file2, comment=None, source=None):
+    difference = compare_files(file1, file2, source=source, diff_content_only=diff_content_only)
     if comment:
         if difference is None:
             difference = Difference(None, file1.name, file2.name)
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index 5962723..903998f 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -132,13 +132,16 @@ class Container(object, metaclass=abc.ABCMeta):
                     p.step(msg=other_member.progress_name)
                     yield MissingFile('/dev/null', other_member), other_member, NO_COMMENT
 
-    def compare(self, other, source=None):
+    def compare(self, other, source=None, no_recurse=False):
         from .compare import compare_commented_files
-
-        return itertools.starmap(
-            compare_commented_files,
-            self.comparisons(other),
-        )
+        from ..directory import Directory
+
+        def hide_trivial_dirs(fst, snd, comment):
+            return not (isinstance(fst, Directory) and isinstance(snd, Directory) and comment == NO_COMMENT)
+        def compare(*args):
+            return compare_commented_files(no_recurse, *args)
+        return itertools.starmap(compare,
+            (x for x in self.comparisons(other) if hide_trivial_dirs(*x)))
 
 
 class MissingContainer(Container):
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index e5f6a9f..ff0774f 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -197,13 +197,12 @@ class File(object, metaclass=abc.ABCMeta):
         if self.as_container:
             # Don't recursve forever on archive quines, etc.
             depth = self._as_container.depth
-            if depth >= Config().max_container_depth:
+            no_recurse = (depth >= Config().max_container_depth)
+            if no_recurse:
                 msg = "Reached max container depth ({})".format(depth)
                 logger.debug(msg)
                 difference.add_comment(msg)
-                return difference
-
-            details.extend(self.as_container.compare(other.as_container))
+            details.extend(self.as_container.compare(other.as_container, no_recurse=no_recurse))
 
         details = [x for x in details if x]
         if not details:
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index 4487da2..5056f0e 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -94,9 +94,9 @@ def test_identification_of_data_tar(deb1, deb2, monkeypatch):
 def test_skip_comparison_of_known_identical_files(deb1, deb2, monkeypatch):
     compared = set()
     orig_func = diffoscope.comparators.utils.compare.compare_files
-    def probe(file1, file2, source=None):
+    def probe(file1, file2, **kwargs):
         compared.add(file1.name)
-        return orig_func(file1, file2, source=None)
+        return orig_func(file1, file2, **kwargs)
     monkeypatch.setattr(diffoscope.comparators.utils.compare, 'compare_files', probe)
     deb1.compare(deb2)
     assert './usr/share/doc/test/README.Debian' not in compared

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


More information about the diffoscope mailing list