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)
| 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). |
| 19 | func 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 |
no outgoing calls