-
Notifications
You must be signed in to change notification settings - Fork 321
pass context to dyff to display the context of changes in multiline diffs #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,9 @@ func printDyffReport(r *Report, to io.Writer) { | |
| _ = os.Remove(newFile.Name()) | ||
| }() | ||
|
|
||
| context := -1 | ||
| for _, entry := range r.Entries { | ||
| context = entry.Context | ||
| _, _ = currentFile.WriteString("---\n") | ||
| _, _ = newFile.WriteString("---\n") | ||
| for _, record := range entry.Diffs { | ||
|
|
@@ -116,6 +118,11 @@ func printDyffReport(r *Report, to io.Writer) { | |
| OmitHeader: true, | ||
| MinorChangeThreshold: 0.1, | ||
| } | ||
|
|
||
| if context != -1 { | ||
| reportWriter.MultilineContextLines = context | ||
| } | ||
|
Comment on lines
+122
to
+124
|
||
|
|
||
| _ = reportWriter.WriteReport(to) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contextis taken from eachReportEntryinside 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 differentContextvalues (e.g., OWNERSHIP entries currently useContext=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 settingMultilineContextLines.