aiven
aiven

Reputation: 4323

How to merge two texts given the common base version of both texts?

Similar to how git merge two branches but:

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?

Upvotes: 2

Views: 163

Answers (0)

Related Questions