MCPcopy Create free account
hub / github.com/sergi/go-diff / PatchMake

Method PatchMake

diffmatchpatch/patch.go:158–180  ·  view source on GitHub ↗

PatchMake computes a list of patches.

(opt ...interface{})

Source from the content-addressed store, hash-verified

156
157// PatchMake computes a list of patches.
158func (dmp *DiffMatchPatch) PatchMake(opt ...interface{}) []Patch {
159 if len(opt) == 1 {
160 diffs, _ := opt[0].([]Diff)
161 text1 := dmp.DiffText1(diffs)
162 return dmp.PatchMake(text1, diffs)
163 } else if len(opt) == 2 {
164 text1 := opt[0].(string)
165 switch t := opt[1].(type) {
166 case string:
167 diffs := dmp.DiffMain(text1, t, true)
168 if len(diffs) > 2 {
169 diffs = dmp.DiffCleanupSemantic(diffs)
170 diffs = dmp.DiffCleanupEfficiency(diffs)
171 }
172 return dmp.PatchMake(text1, diffs)
173 case []Diff:
174 return dmp.patchMake2(text1, t)
175 }
176 } else if len(opt) == 3 {
177 return dmp.PatchMake(opt[0], opt[2])
178 }
179 return []Patch{}
180}
181
182// patchMake2 computes a list of patches to turn text1 into text2.
183// text2 is not provided, diffs are the delta between text1 and text2.

Callers 15

TestPatchSplitMaxFunction · 0.80
TestPatchAddPaddingFunction · 0.80
TestPatchApplyFunction · 0.80
TestPatchMakeInvalidUTF8Function · 0.80
BenchmarkPatchFromTextFunction · 0.80
BenchmarkPatchApplyFunction · 0.80
BenchmarkPatchSplitMaxFunction · 0.80

Calls 5

DiffText1Method · 0.95
DiffMainMethod · 0.95
DiffCleanupSemanticMethod · 0.95
DiffCleanupEfficiencyMethod · 0.95
patchMake2Method · 0.95

Tested by 15

TestPatchSplitMaxFunction · 0.64
TestPatchAddPaddingFunction · 0.64
TestPatchApplyFunction · 0.64
TestPatchMakeInvalidUTF8Function · 0.64
BenchmarkPatchFromTextFunction · 0.64
BenchmarkPatchApplyFunction · 0.64
BenchmarkPatchSplitMaxFunction · 0.64