0

This is related to version control, in a parallel modification situation where we do not know the exact timing of changes, so we assume that we receive two modified versions of a file at the same time. I simplify the problem:

I have a string S, with two modified versions, called T and U. I can see the differences between S and T using diff. Let's call the patch made out of T over S, as PT. The same for U, we will have PU. Now, I want to merge PT and PU into one single patch, in a safe way, being able to detect the conflicts between PT and PU at a "word" level, not the typical programming line level.

questions:

1- Is there such an algorithm to merge two patches?

2- How can I detect the conflicts between T and U?

3- What's a common policy for dealing with conflicts? to me, one solution is to always choose the changes from one of the versions, say T, in case of a conflict.

Are there any tools out there to do what I am looking for?

nvd_ai
  • 1,060
  • 11
  • 20

2 Answers2

0

There is no word-level conflict resolution tools that I can think of. You always compare lines.

You could write a custom driver for your file type. I believe this is done through git attributes. Here you could do what ever you like if the merge is a non-fast-forward merge.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Is it theoretically impossible to write an algorithm for conflict resolution at the word-level? for instance, what if I am dealing with text documents and two different modifications are made to the same line even without really conflicting? – nvd_ai May 22 '12 at 21:35
  • @nvd_ai - If it was not possible then tools like WinDiff would not exists. The question is are you able to write one yourself. – Security Hound May 23 '12 at 11:06
  • @Ramhound: I assume the algorithm to merge this already exists and I am a capable developer to implement it. I do not want to reinvent the wheel. It would be more helpful if you could suggest a solution/algorithm for this. – nvd_ai May 23 '12 at 15:36
0

I am not aware of any implementation that does this, however you can get good help from using a merge tool that detects and shows differences within the line. KDiff3 is such a tool. In the following example you want to merge both the unsigned and int n changes. This is done by manually editing the merge output, but the tool makes this operation very simple (to the point that the only hard part is to understand the code changes).

KDiff3 screenshot

hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • Yes. so this visualizes the situation I am talking about. I am wondering if there is an algorithm to merge these two lines correctly because at the word level there is no conflict between these two modifications. – nvd_ai May 23 '12 at 15:33