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

Function CreatePatch

internal/diff/diff.go:19–23  ·  view source on GitHub ↗

CreatePatch computes a compact patch that transforms oldText into newText. The patch can be applied with ApplyPatch to recover newText from oldText. Both texts must be valid UTF-8 (BUG-3839; see ReversePatch).

(oldText, newText string)

Source from the content-addressed store, hash-verified

17// The patch can be applied with ApplyPatch to recover newText from oldText.
18// Both texts must be valid UTF-8 (BUG-3839; see ReversePatch).
19func CreatePatch(oldText, newText string) string {
20 diffs := dmp.DiffMain(oldText, newText, true)
21 patches := dmp.PatchMake(oldText, diffs)
22 return dmp.PatchToText(patches)
23}
24
25// ApplyPatch applies a patch to baseText to produce the target text.
26// Returns an error if the patch cannot be applied cleanly, or if the base or

Calls

no outgoing calls