[diffoscope] 01/02: Comparison of containers using different formats.
Maria Glukhova
siamezzze-guest at moszumanska.debian.org
Fri Jan 20 06:11:06 CET 2017
This is an automated email from the git hooks/post-receive script.
siamezzze-guest pushed a commit to branch siamezzze/containers
in repository diffoscope.
commit f6456a883b70400ba8595ba352fb88142c3fbc50
Author: Maria Glukhova <siamezzze at gmail.com>
Date: Tue Jan 17 20:35:43 2017 +0200
Comparison of containers using different formats.
---
diffoscope/comparators/utils/compare.py | 37 +++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/diffoscope/comparators/utils/compare.py b/diffoscope/comparators/utils/compare.py
index 80053c7..e74fe2d 100644
--- a/diffoscope/comparators/utils/compare.py
+++ b/diffoscope/comparators/utils/compare.py
@@ -33,6 +33,8 @@ from ..missing_file import MissingFile
from .command import Command
from .specialize import specialize
+from .archive import Archive
+from .libarchive import LibarchiveContainer
try:
import tlsh
@@ -60,6 +62,39 @@ def compare_root_paths(path1, path2):
file2 = specialize(FilesystemFile(path2, container=container2))
return compare_files(file1, file2)
+def compare_containers(file1, file2, source=None):
+ logger.debug("Both files are containers.")
+ difference = Difference(None, file1.name, file2.name, source=source)
+ details = []
+ container1 = file1.as_container
+ container2 = file2.as_container
+ details.extend([Difference.from_text(
+ container1.__class__.__name__,
+ container2.__class__.__name__,
+ file1.name,
+ file2.name,
+ source="container type"
+ )])
+ details.extend([Difference.from_text(
+ "\n".join(container1.get_member_names()),
+ "\n".join(container2.get_member_names()),
+ file1.name,
+ file2.name,
+ source="file list"
+ )])
+
+ if isinstance(container1, LibarchiveContainer) == \
+ isinstance(container2, LibarchiveContainer):
+ logger.debug("Comparing content.")
+ details.extend(container1.compare(container2))
+ else:
+ logger.debug("Can't compare libarchive with regular container, "
+ "falling back to binary diff.")
+ details.extend([file1.compare_bytes(file2, source)])
+ details = [d for d in details if d is not None]
+ difference.add_details(details)
+ return difference
+
def compare_files(file1, file2, source=None):
logger.debug("Comparing files %s and %s", file1, file2)
with profile('has_same_content_as', file1):
@@ -73,6 +108,8 @@ def compare_files(file1, file2, source=None):
elif isinstance(file2, MissingFile):
file2.other_file = file1
elif file1.__class__.__name__ != file2.__class__.__name__:
+ if file1.as_container and file2.as_container:
+ return compare_containers(file1, file2, source)
return file1.compare_bytes(file2, source)
with profile('compare_files (cumulative)', file1):
return file1.compare(file2, source)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list