Skip to content

Commit 54eda8c

Browse files
Support plassing autojunk and a custom line-junk hook in LineDiff Params.
1 parent 7121d2b commit 54eda8c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

difflib/difflib.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,16 @@ func formatRangeUnified(start, stop int) string {
792792

793793
// Unified diff parameters
794794
type LineDiffParams struct {
795-
A []string // First sequence lines
796-
FromFile string // First file name
797-
FromDate string // First file time
798-
B []string // Second sequence lines
799-
ToFile string // Second file name
800-
ToDate string // Second file time
801-
Eol string // Headers end of line, defaults to LF
802-
Context int // Number of context lines
795+
A []string // First sequence lines
796+
FromFile string // First file name
797+
FromDate string // First file time
798+
B []string // Second sequence lines
799+
ToFile string // Second file name
800+
ToDate string // Second file time
801+
Eol string // Headers end of line, defaults to LF
802+
Context int // Number of context lines
803+
AutoJunk bool // If true, use autojunking
804+
IsJunkLine func(string)bool // How to spot junk lines
803805
}
804806

805807
// Compare two sequences of lines; generate the delta as a unified diff.
@@ -841,6 +843,9 @@ func WriteUnifiedDiff(writer io.Writer, diff LineDiffParams) error {
841843

842844
started := false
843845
m := NewMatcher(diff.A, diff.B)
846+
if diff.AutoJunk || diff.IsJunkLine != nil {
847+
m = NewMatcherWithJunk(diff.A, diff.B, diff.AutoJunk, diff.IsJunkLine)
848+
}
844849
for _, g := range m.GetGroupedOpCodes(diff.Context) {
845850
if !started {
846851
started = true
@@ -973,6 +978,9 @@ func WriteContextDiff(writer io.Writer, diff LineDiffParams) error {
973978

974979
started := false
975980
m := NewMatcher(diff.A, diff.B)
981+
if diff.AutoJunk || diff.IsJunkLine != nil {
982+
m = NewMatcherWithJunk(diff.A, diff.B, diff.AutoJunk, diff.IsJunkLine)
983+
}
976984
for _, g := range m.GetGroupedOpCodes(diff.Context) {
977985
if !started {
978986
started = true

0 commit comments

Comments
 (0)