[diffoscope] 02/02: Refactor DirectoryContainer to be more similar to Container

Ximin Luo infinity0 at debian.org
Wed May 24 22:57:31 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 86474589d2bfea53c2766f998fee6c8bb0879304
Author: Ximin Luo <infinity0 at debian.org>
Date:   Wed May 24 22:57:21 2017 +0200

    Refactor DirectoryContainer to be more similar to Container
    
    This will make it easier to improve the progressbar logic
---
 diffoscope/comparators/directory.py       | 32 ++++++++++++++++++-------------
 diffoscope/comparators/utils/container.py |  8 +++++---
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index 6116f28..91535a9 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
+import itertools
 import os
 import re
 import logging
@@ -189,25 +190,30 @@ class DirectoryContainer(Container):
         else:
             return FilesystemFile(os.path.join(self.source.path, member_name), container=self)
 
-    def compare(self, other, source=None):
-        from .utils.compare import compare_files
-
-        differences = []
+    def comparisons(self, other):
         my_names = self.get_member_names()
         other_names = other.get_member_names()
         to_compare = set(my_names).intersection(other_names)
         to_compare = set(filter_excludes(to_compare))
+
         with Progress(len(to_compare)) as p:
             for name in sorted(to_compare):
                 my_file = self.get_member(name)
                 other_file = other.get_member(name)
-                inner_difference = compare_files(
-                                       my_file, other_file, source=name)
-                meta_differences = compare_meta(my_file.name, other_file.name)
-                if meta_differences and not inner_difference:
-                    inner_difference = Difference(None, my_file.path, other_file.path)
-                if inner_difference:
-                    inner_difference.add_details(meta_differences)
-                    differences.append(inner_difference)
+                yield my_file, other_file, name
                 p.step(msg=name)
-        return differences
+
+    def compare(self, other, source=None):
+        from .utils.compare import compare_files
+
+        def compare_pair(file1, file2, source):
+            inner_difference = compare_files(
+                                   file1, file2, source=source)
+            meta_differences = compare_meta(file1.name, file2.name)
+            if meta_differences and not inner_difference:
+                inner_difference = Difference(None, file1.path, file2.path)
+            if inner_difference:
+                inner_difference.add_details(meta_differences)
+            return inner_difference
+
+        return filter(None, itertools.starmap(compare_pair, self.comparisons(other)))
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index c940bb4..d46b085 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -134,15 +134,17 @@ class Container(object, metaclass=abc.ABCMeta):
                     yield MissingFile('/dev/null', other_member), other_member, NO_COMMENT
 
     def compare(self, other, source=None, no_recurse=False):
-        def compare(file1, file2, comment):
-            from .compare import compare_files
+        from .compare import compare_files
+
+        def compare_pair(file1, file2, comment):
             difference = compare_files(file1, file2, source=None, diff_content_only=no_recurse)
             if comment:
                 if difference is None:
                     difference = Difference(None, file1.name, file2.name)
                 difference.add_comment(comment)
             return difference
-        return filter(None, itertools.starmap(compare, self.comparisons(other)))
+
+        return filter(None, itertools.starmap(compare_pair, self.comparisons(other)))
 
 
 class MissingContainer(Container):

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


More information about the diffoscope mailing list