google / diff-match-patch

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.
Apache License 2.0
7.47k stars 1.11k forks source link

confuse about diff-match-path compute results on microsoft TODO app, can somebody give some tips? #120

Open initlifeinc opened 3 years ago

initlifeinc commented 3 years ago

I try to understand how diff-match-patch works on Microsoft TODO app.

So i try to create a case about different copies on a base text , and use diff-match-patch to resolve to get a final result, and compared it with the result got from Microsoft TODO app.

The following is my case: Here i define some names to indicate the case texts. -----------------define begin----------------------- BaseText I am the very model of a cartoon individual, My animation's comical, unusual, and whimsical, I'm quite adept at funny gags, comedic theory I have read, From wicked puns and stupid jokes to anvils that drop on your head.

TextA: I am the very model of a modern Major-General, I've information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical.

TextB: I am the very model of a cartoon individual, xxxxx My animation's comical, unusual, and whimsical, I'm quite adept at funny gags, comedic theory I have read, From wicked puns and stupid jokes to anvils that drop on your head.

FinalResultText: I am the very model of a modern Major-Generxxx My aniI'veformation vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical, From Marathon to Waterloo, in order categorical.

------------------define end-----------------

The change timeline is:

  1. First UserA and UserB are all BaseText
  2. UserA change BaseText to TextA in online status, but UserB is offline status.
  3. After UserA finish change, UserB change his BaseText to TextB under offline status.
  4. UserB switch the network on, commit it changes to server.
  5. wait for a while, for Microsoft TODO App, both UserA and UserB change their texts to FinalResultText. But on this demo(https://neil.fraser.name/software/diff_match_patch/demos/patch.html), the result text is TextA.

I can understand that on patch demo, patch of UserB changes cannot patch on TextA, so the final result is TextA. But i cannot understand why Microsoft use DiffMatchPatch but the result is FinalResultText.

Any body known why it is?

dmsnell commented 3 years ago

It's not going to be easy to know what Microsoft is doing in their app without inspecting the code. As far as diff-match-patch is concerned though it should not apply patches that are unresolvable automatically. In this case, we cannot reconcile the differences without choosing which differences we want to preserve.

It is possible to apply an invalid patch and it looks like that happened here. In the first line it looks like UserB's changes were applied first and then the patch submitted by UserA was applied over it. Line three seems to contradict this theory. Patches can specify ranges of text to keep, delete, or insert. They don't specify "change this old thing to this new thing" so if you apply them to the wrong text you will get gibberish.

initlifeinc commented 3 years ago

Got it