[Git][reproducible-builds/diffoscope][master] Add a --diff-context option to control unified diff context size....
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Wed Sep 15 07:58:57 UTC 2021
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
1ee45568 by Benjamin Peterson at 2021-09-15T08:58:23+01:00
Add a --diff-context option to control unified diff context size. (reproducible-builds/diffoscope!88)
Signed-off-by: Chris Lamb <lamby at debian.org>
- - - - -
4 changed files:
- diffoscope/config.py
- diffoscope/diff.py
- diffoscope/main.py
- tests/test_difference.py
Changes:
=====================================
diffoscope/config.py
=====================================
@@ -39,6 +39,8 @@ class Config:
self.reset()
def reset(self):
+ self.diff_context = 7
+
# GNU diff cannot process arbitrary large files :(
self.max_diff_input_lines = 2 ** 22
self.max_diff_block_lines_saved = float("inf")
=====================================
diffoscope/diff.py
=====================================
@@ -172,7 +172,13 @@ class DiffParser:
@tool_required("diff")
def run_diff(fifo1, fifo2, end_nl_q1, end_nl_q2):
- cmd = [get_tool_name("diff"), "-aU7", fifo1, fifo2]
+ cmd = [
+ get_tool_name("diff"),
+ "-a",
+ "-U" + str(Config().diff_context),
+ fifo1,
+ fifo2,
+ ]
logger.debug("Running %s", " ".join(cmd))
=====================================
diffoscope/main.py
=====================================
@@ -218,6 +218,14 @@ def create_parser():
group2 = parser.add_argument_group("output limits")
# everything marked with default=None below is affected by no-default-limits
+ group2.add_argument(
+ "--diff-context",
+ metavar="LINES",
+ type=int,
+ help="Lines of unified diff context to show. (default: %d)"
+ % Config().diff_context,
+ default=Config().diff_context,
+ )
group2.add_argument(
"--max-text-report-size",
metavar="BYTES",
@@ -613,6 +621,7 @@ def configure(parsed_args):
elif parsed_args.no_default_limits:
setattr(Config(), x, float("inf"))
+ Config().diff_context = parsed_args.diff_context
Config().max_page_size = parsed_args.max_page_size
Config().max_page_diff_block_lines = parsed_args.max_page_diff_block_lines
=====================================
tests/test_difference.py
=====================================
@@ -133,3 +133,13 @@ def test_non_str_arguments_to_source1_source2():
with pytest.raises(TypeError):
Difference.from_text_readers(a, b, *x)
+
+
+def test_adjust_diff_context(monkeypatch):
+ monkeypatch.setattr(Config(), "diff_context", 2)
+ a = io.StringIO("".join(str(i) + "\n" for i in range(20)))
+ b = io.StringIO(
+ "".join(str(i if i != 10 else "x") + "\n" for i in range(20))
+ )
+ difference = Difference.from_text_readers(a, b, "a", "b")
+ assert difference.unified_diff.count("\n") == 7
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/1ee45568a0f1bd2942a1206bbba5e592419634b5
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/1ee45568a0f1bd2942a1206bbba5e592419634b5
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20210915/c1f9765f/attachment.htm>
More information about the rb-commits
mailing list