Commit 498edb52 authored by Ximin Luo's avatar Ximin Luo

More long-term fix for the shared-singleton issue

parent 9844353f
......@@ -58,15 +58,9 @@ def compare_root_paths(path1, path2):
if any_excluded(path1, path2):
return None
default_metadata = Config().exclude_directory_metadata is None
if os.path.isdir(path1) and os.path.isdir(path2):
if default_metadata:
Config().exclude_directory_metadata = False
return compare_directories(path1, path2)
if default_metadata:
Config().exclude_directory_metadata = True
container1 = FilesystemDirectory(os.path.dirname(path1)).as_container
file1 = specialize(FilesystemFile(path1, container=container1))
container2 = FilesystemDirectory(os.path.dirname(path2)).as_container
......
......@@ -29,36 +29,41 @@ class defaultint(int):
pass
# Avoid setting values on this anywhere other than main.run_diffoscope(),
# otherwise tests may fail unpredictably depending on order-of-execution.
class Config(object):
# GNU diff cannot process arbitrary large files :(
max_diff_input_lines = 2 ** 22
max_diff_block_lines_saved = float("inf")
# hard limits, restricts single-file and multi-file formats
max_report_size = defaultint(40 * 2 ** 20) # 40 MB
max_diff_block_lines = defaultint(2 ** 10) # 1024 lines
# structural limits, restricts single-file formats
# semi-restricts multi-file formats
max_page_size = defaultint(400 * 2 ** 10) # 400 kB
max_page_size_child = defaultint(200 * 2 ** 10) # 200 kB
max_page_diff_block_lines = defaultint(2 ** 7) # 128 lines
max_text_report_size = 0
new_file = False
fuzzy_threshold = 60
enforce_constraints = True
excludes = ()
exclude_commands = ()
exclude_directory_metadata = False
compute_visual_diffs = False
max_container_depth = 50
force_details = False
_singleton = {}
def __init__(self):
self.__dict__ = self._singleton
if not self._singleton:
self.reset()
def reset(self):
# GNU diff cannot process arbitrary large files :(
self.max_diff_input_lines = 2 ** 22
self.max_diff_block_lines_saved = float("inf")
# hard limits, restricts single-file and multi-file formats
self.max_report_size = defaultint(40 * 2 ** 20) # 40 MB
self.max_diff_block_lines = defaultint(2 ** 10) # 1024 lines
# structural limits, restricts single-file formats
# semi-restricts multi-file formats
self.max_page_size = defaultint(400 * 2 ** 10) # 400 kB
self.max_page_size_child = defaultint(200 * 2 ** 10) # 200 kB
self.max_page_diff_block_lines = defaultint(2 ** 7) # 128 lines
self.max_text_report_size = 0
self.new_file = False
self.fuzzy_threshold = 60
self.enforce_constraints = True
self.excludes = ()
self.exclude_commands = ()
self.exclude_directory_metadata = False
self.compute_visual_diffs = False
self.max_container_depth = 50
self.force_details = False
def __setattr__(self, k, v):
super(Config, self).__setattr__(k, v)
......
......@@ -382,6 +382,12 @@ def run_diffoscope(parsed_args):
else:
difference = load_diff_from_path(path1)
else:
if Config().exclude_directory_metadata is None:
if os.path.isdir(path1) and os.path.isdir(path2):
Config().exclude_directory_metadata = False
else:
Config().exclude_directory_metadata = True
logger.debug('Starting comparison')
with Progress():
with profile('main', 'outputs'):
......@@ -426,6 +432,10 @@ def main(args=None):
pdb.post_mortem()
sys.exit(2)
finally:
# Helps our tests run more predictably - some of them call main()
# which sets Config() values.
Config().reset()
with profile('main', 'cleanup'):
clean_all_temp_files()
......
......@@ -58,10 +58,6 @@ def differences(tmpdir):
os.utime(str(tmpdir.join('b/dir')), (0, 0))
os.utime(str(tmpdir.join('a')), (0, 0))
os.utime(str(tmpdir.join('b')), (0, 0))
# Earlier tests set this to True, unfortunately.
# i.e. the Config() singleton pattern does not play nicely
# with our tests, eventually that should be cleaned up.
Config().exclude_directory_metadata = False
return compare_directories(str(tmpdir.join('a')), str(tmpdir.join('b'))).details
......
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