MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / FormatDiffSummary

Function FormatDiffSummary

internal/diff/diff.go:140–157  ·  view source on GitHub ↗

FormatDiffSummary returns a human-readable summary of changes. Its "lines" are character-diff CHUNKS (a one-character edit reads +1/-1); LineCounts is the line-level count the version rows store (PLAN-2348 U2).

(oldText, newText string)

Source from the content-addressed store, hash-verified

138// are character-diff CHUNKS (a one-character edit reads +1/-1); LineCounts is
139// the line-level count the version rows store (PLAN-2348 U2).
140func FormatDiffSummary(oldText, newText string) string {
141 oldLines := strings.Count(oldText, "\n")
142 newLines := strings.Count(newText, "\n")
143 added := 0
144 removed := 0
145 diffs := dmp.DiffMain(oldText, newText, false)
146 for _, d := range diffs {
147 switch d.Type {
148 case difflib.DiffInsert:
149 added += strings.Count(d.Text, "\n") + 1
150 case difflib.DiffDelete:
151 removed += strings.Count(d.Text, "\n") + 1
152 }
153 }
154 _ = oldLines
155 _ = newLines
156 return fmt.Sprintf("+%d/-%d lines", added, removed)
157}
158
159// LineCounts returns how many lines a line-level diff of oldText → newText
160// adds and removes (PLAN-2348 U2). It counts the way the web DiffView renders

Calls 1

CountMethod · 0.80

Tested by 1