Commit 35d48f9d authored by Ximin Luo's avatar Ximin Luo

difference: Don't truncate diff output by default, and use a separate flag when doing so

Previously, max-diff-block-lines would also (on top of altering html output)
interfere with diff's output on a deeper level, hiding it from all presenters.
This was surprising with --text output since it does not honour max-report-size
and is meant to be a "pure-by-default" output that shows everything.

So now we move this behaviour to a separate flag, max-diff-block-lines-saved,
and document it more clearly. Most users should not need this, unless they keep
running out of memory.
parent 9d804217
......@@ -29,6 +29,7 @@ class Config(object):
def __init__(self):
self._max_diff_block_lines = 1024
self._max_diff_block_lines_parent = 50
self._max_diff_block_lines_saved = float("inf")
self._max_diff_input_lines = 2 ** 20 # GNU diff cannot process arbitrary large files :(
self._max_report_size = 2000 * 2 ** 10 # 2000 kB
self._max_report_child_size = 500 * 2 ** 10
......@@ -45,6 +46,9 @@ class Config(object):
if self._max_diff_block_lines < self._max_diff_block_lines_parent:
raise ValueError("max_diff_block_lines (%s) cannot be smaller than max_diff_block_lines_parent (%s)" %
(self._max_diff_block_lines, self._max_diff_block_lines_parent))
if self._max_diff_block_lines_saved < self._max_diff_block_lines:
raise ValueError("max_diff_block_lines_saved (%s) cannot be smaller than max_diff_block_lines (%s)" %
(self._max_diff_block_lines_saved, self._max_diff_block_lines))
@property
def max_diff_block_lines(self):
......@@ -64,6 +68,15 @@ class Config(object):
self._max_diff_block_lines_parent = value
self._check_constraints()
@property
def max_diff_block_lines_saved(self):
return self._max_diff_block_lines_saved
@max_diff_block_lines_saved.setter
def max_diff_block_lines_saved(self, value):
self._max_diff_block_lines_saved = value
self._check_constraints()
@property
def max_diff_input_lines(self):
return self._max_diff_input_lines
......
......@@ -113,7 +113,7 @@ class DiffParser(object):
else:
self._block_len = 1
self._direction = line[0]
max_lines = Config.general.max_diff_block_lines
max_lines = Config.general.max_diff_block_lines_saved
if self._block_len >= max_lines:
return self.skip_block
else:
......@@ -123,7 +123,7 @@ class DiffParser(object):
def skip_block(self, line):
if self._remaining_hunk_lines == 0 or line[0] != self._direction:
removed = self._block_len - Config.general.max_diff_block_lines
removed = self._block_len - Config.general.max_diff_block_lines_saved
if removed:
self._diff.write('%s[ %d lines removed ]\n' % (self._direction, removed))
return self.read_hunk(line)
......
......@@ -100,6 +100,14 @@ def create_parser():
'--no-default-limits)',
default=Config.general.max_diff_block_lines_parent).completer=RangeCompleter(0,
Config.general.max_diff_block_lines_parent, 200)
parser.add_argument('--max-diff-block-lines-saved', dest='max_diff_block_lines_saved',
metavar='LINES', type=int,
help='Maximum number of lines saved per diff block. '
'Most users should not need this, unless you run out '
'of memory. This truncates diff(1) output before even '
'trying to emit it in a report; also affects --text '
'output. (0 to disable, default: 0)',
default=0).completer=RangeCompleter(0, 0, 200)
parser.add_argument('--max-diff-input-lines', dest='max_diff_input_lines',
metavar='LINES', type=int,
help='Maximum number of lines fed to diff(1). '
......@@ -193,6 +201,7 @@ def run_diffoscope(parsed_args):
maybe_set_limit(Config.general, parsed_args, "max_report_size")
maybe_set_limit(Config.general, parsed_args, "max_report_child_size")
# need to set them in this order due to Config._check_constraints
maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines_saved")
maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines_parent")
maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines")
maybe_set_limit(Config.general, parsed_args, "max_diff_input_lines")
......
This diff is collapsed.
......@@ -32,7 +32,7 @@ def test_too_much_input_for_diff(monkeypatch):
assert '[ Too much input for diff ' in difference.unified_diff
def test_too_long_diff_block_lines(monkeypatch):
monkeypatch.setattr(Config, 'max_diff_block_lines', 10)
monkeypatch.setattr(Config, 'max_diff_block_lines_saved', 10)
too_long_text_a = io.StringIO("a\n" * 21)
too_long_text_b = io.StringIO("b\n" * 21)
difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, 'a', 'b')
......
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