pass context to dyff to display the context of changes in multiline diffs#934
pass context to dyff to display the context of changes in multiline diffs#934nikitka wants to merge 1 commit intodatabus23:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR wires the existing --context/-C option into dyff’s multiline diff rendering so dyff can show surrounding context lines within multiline YAML value changes, improving readability of multiline diffs.
Changes:
- Capture the report entry context value during dyff report generation.
- Set
dyff.HumanReport.MultilineContextLinesbased on the captured context (when not-1).
| context := -1 | ||
| for _, entry := range r.Entries { | ||
| context = entry.Context | ||
| _, _ = currentFile.WriteString("---\n") |
There was a problem hiding this comment.
context is taken from each ReportEntry inside the loop and the final value (from the last entry) is applied to the whole dyff report. This makes the dyff multiline context setting dependent on entry ordering and can produce the wrong value when entries have different Context values (e.g., OWNERSHIP entries currently use Context=0). Consider deriving the value once from the global option (or from the first non-ownership/non-(-1) entry) and/or validating that all entries share the same context before setting MultilineContextLines.
| if context != -1 { | ||
| reportWriter.MultilineContextLines = context | ||
| } |
There was a problem hiding this comment.
This change introduces new behavior (wiring --context/-C into dyff via MultilineContextLines) but there’s no automated test coverage for dyff report output/behavior in the diff package. Adding a focused unit test that exercises a multiline YAML value change and asserts the presence/absence of context lines based on Context would help prevent regressions across dyff version changes.
dyffcan show context lines of multiline YAML value changes. the helm-diff plugin has context option. With this PR, I propose passing this context option todyffas theMultilineContextLinesoption. This will help betterunderstand what has changed in multiline values.For example, without passion
MultilineContextLinesI get the following output:It looks like one block was changed; however, I actually modified different part of the multiline value. With passing 3 context lines, the diff looks much clearer: