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)
| 21 | // The patch can be applied with ApplyPatch to recover newText from oldText. |
| 22 | // Both texts must be valid UTF-8 (BUG-3839; see ReversePatch). |
| 23 | func CreatePatch(oldText, newText string) string { |
| 24 | diffs := dmp.DiffMain(oldText, newText, true) |
| 25 | patches := dmp.PatchMake(oldText, diffs) |
| 26 | return dmp.PatchToText(patches) |
| 27 | } |
| 28 | |
| 29 | // ApplyPatch applies a patch to baseText to produce the target text. |
| 30 | // Returns an error if the patch cannot be applied cleanly, or if the base or |
no outgoing calls