views:

673

answers:

3

So I've been working on a wiki type site. What I'm trying to decide on is what the best algorithm for merging an article that is simultaneously being edited by two users.

So far I'm considering using Wikipedia's method of merging the documents if two unrelated areas are edited, but throwing away the older change if two commits conflict.

My question is as follows: If I have the original article, and two changes to it, what are the best algorithms to merge them and then deal with conflicts as they arise?

A: 

Rather than implement what is a complex algorithm yourself, why not use a third-party tool (such as SourceGear's DiffMerge which is free). Most of them have command line versions that you could shell out to, to perform the merge.

Mitch Wheat
Mainly because I'm in a situation where I don't know what OS I'll be running on or software will be on the system. If you know of any foss php versions, I'd be willing to look at those.
icco
+1  A: 

Frankly, I'd rely on diff3. It's on pretty much every Unix distro, and you can always build and bundle an .EXE for Windows to ensure it is there for your purposes.

Will Hartung
+4  A: 

Bill Ritcher's excellent paper "A Trustworthy 3-Way Merge" talks about some of the common gotchas with three way merging and clever solutions to them that commercial SCM packages have used.

The 3-way merge will automatically apply all the changes (which are not overlapping) from each version. The trick is to automatically handle as many almost overlapping regions as possible.

Kyle Wiens
Cool paper, thanks for the link!
icco
I change the URL because the one you had given is now 404. I hope it's still referring to the same article.
ChrisW
Yup, that's it. Thanks for updating it!
Kyle Wiens