2

Similar to how git merge two branches but:

  • using python
  • instead of two branches we have text1 and text2
  • instead of common commit we have text0 - previous version of both text1 and text2

diff-match-patch probably can be used to accomplish this task, but I didn't find appropriate method neither in doc nor in python package source code (because docs are not complete).

So far I come up with this:

c = "some base text with meaning"
a = "changed base text with meaning"
b = "some base text without meaning"
p1 = dmp.patch_make(c, a)
p2 = dmp.patch_make(c, b)
dmp.patch_apply(p1 + p2, c)
> ('changed base text without meaning', [True, True])

It looks like it works, but I'm not sure if this is correct method. Can someone experienced with diff-match-patch approve this?

aiven
  • 3,775
  • 3
  • 27
  • 52
  • I guess it is correct as long as it does the work. Is the conflict handling (or lack thereof) enough for your needs? What do you expect to happen when `a = 'some base text with foo'` and `b = 'some base text with bar'`? – Stop harming Monica Feb 21 '19 at 18:52

0 Answers0