Commit 8ab261e3 authored by Ximin Luo's avatar Ximin Luo

comparators: add a --force-details flag for debugging

Helps to reproduce #875282 using one single deb, without needing two
actually-differing debs
parent 6e42152b
......@@ -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")]
......
......@@ -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):
......
......@@ -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
......
......@@ -43,6 +43,7 @@ class Config(object):
exclude_directory_metadata = False
compute_visual_diffs = False
max_container_depth = 50
force_details = False
_singleton = {}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment