[diffoscope] 01/01: comparators: add a --force-details flag for debugging
Ximin Luo
infinity0 at debian.org
Wed Sep 20 18:24:35 CEST 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit 8ab261e3569ccf0b713a7d7af03bb1ffc94f9ab2
Author: Ximin Luo <infinity0 at debian.org>
Date: Wed Sep 20 18:24:03 2017 +0200
comparators: add a --force-details flag for debugging
Helps to reproduce #875282 using one single deb, without needing two
actually-differing debs
---
diffoscope/comparators/deb.py | 3 ++-
diffoscope/comparators/utils/compare.py | 14 +++++++++-----
diffoscope/comparators/utils/file.py | 2 +-
diffoscope/config.py | 1 +
diffoscope/main.py | 5 +++++
5 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 9e52acb..aa7f80f 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -23,6 +23,7 @@ import logging
from diffoscope.difference import Difference
from .tar import TarContainer
+from .utils.compare import compare_files
from .utils.file import File
from .utils.archive import ArchiveMember
from .utils.libarchive import LibarchiveContainer, list_libarchive
@@ -150,7 +151,7 @@ class Md5sumsFile(File):
yield " ".join(line.split(" ")[2:])
def compare_details(self, other, source=None):
- return [Difference(None, self.path, other.path, source="md5sums", comment="Files in package differ"),
+ return [compare_files(self, other, source='md5sums', diff_content_only=True),
Difference.from_text_readers(self.strip_checksum(self.path), self.strip_checksum(other.path),
self.path, other.path, source="line order")]
diff --git a/diffoscope/comparators/utils/compare.py b/diffoscope/comparators/utils/compare.py
index 25b92e9..5ef915f 100644
--- a/diffoscope/comparators/utils/compare.py
+++ b/diffoscope/comparators/utils/compare.py
@@ -77,14 +77,18 @@ def compare_files(file1, file2, source=None, diff_content_only=False):
if any_excluded(file1.name, file2.name):
return None
+ force_details = Config().force_details
with profile('has_same_content_as', file1):
- if file1.has_same_content_as(file2):
+ has_same_content = file1.has_same_content_as(file2)
+
+ if has_same_content:
+ if not force_details or diff_content_only:
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
+ elif diff_content_only:
+ assert not has_same_content
+ return Difference(None, file1.name, file2.name, comment="Files differ")
+
specialize(file1)
specialize(file2)
if isinstance(file1, MissingFile):
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index d46c934..14d5412 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -262,7 +262,7 @@ class File(object, metaclass=abc.ABCMeta):
return difference
def has_same_content_as(self, other):
- logger.debug('Binary.has_same_content: %s %s', self, other)
+ logger.debug('File.has_same_content: %s %s', self, other)
if os.path.isdir(self.path) or os.path.isdir(other.path):
return False
# try comparing small files directly first
diff --git a/diffoscope/config.py b/diffoscope/config.py
index aa23d2b..d6e6f84 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -43,6 +43,7 @@ class Config(object):
exclude_directory_metadata = False
compute_visual_diffs = False
max_container_depth = 50
+ force_details = False
_singleton = {}
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 95ce49e..f6ccbe2 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -216,6 +216,10 @@ def create_parser():
'it in a report, and affects all types of output, '
'including --text and --json. (0 to disable, default: '
'%(default)s)', default=0)
+ group3.add_argument('--force-details', default=False, action='store_true',
+ help='Force recursing into the depths of file formats '
+ 'even if files have the same content, only really '
+ 'useful for debugging diffoscope. Default: %(default)s')
group4 = parser.add_argument_group('information commands')
group4.add_argument('--help', '-h', action='help',
@@ -352,6 +356,7 @@ def run_diffoscope(parsed_args):
maybe_set_limit(Config(), parsed_args, "max_diff_block_lines_saved")
maybe_set_limit(Config(), parsed_args, "max_diff_input_lines")
Config().max_container_depth = parsed_args.max_container_depth
+ Config().force_details = parsed_args.force_details
Config().fuzzy_threshold = parsed_args.fuzzy_threshold
Config().new_file = parsed_args.new_file
Config().excludes = parsed_args.excludes
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list