views:

62

answers:

4

I'm trying to code a site that will allow multiple people to be working on a file at the same time. In doing so, the biggest road-block I have come across is merging the new versions of the files, version-control style.

I have been unable to find anything in the vein of a built-in JavaScript or PHP function that will help me with this. The closest I have found is array_diff, which really isn't what I need, since that simply returns what elements are not present in the other array, and if I have an array of words, there are bound to be repeats; additionally, array_diff ignores the number of times something shows up or its position in the file.

I have looked a little into Levenshtein's distance algorithm, which does come built-in as a function with php, but I'm not sure if it's what I need. If so, please tell me, and I will look into that further.

Is there anything that you know of that will suit my needs?

EDIT:

Let me clarify a little. I am not actually designing a version control system. I only want to merge the files, not store old versions, etc. Is installing a CVS or SVN or something along those lines still my best bet just to get use of the one function?

+1  A: 

Why reeinvent the wheel? I'd use exec together with "diff" to find the differences between two files and start working from there.

Still, that won't solve problems that cvs cannot solve, too: if conflicts occur (because two or more persons have been changing the same line of code), you'll have to fix those conflicts manually (or let the editors do it).

But then again: why not use CVS right away and use a web-viewer together with it?
e.g. http://www.viewvc.org

Select0r
+1  A: 

mercurial, subversion, cvs, ... Don't reinvent the wheel indeed.

Cedric
+2  A: 

The core algorithm is LCS.

Which is used to generate the side by side view in programs like WinMerge.

I actually made a web based version but I got stuck on synchronizing the scrolling of the two windows and they went with a clunkier solution.

Gabriel
+1  A: 

See EtherPad

Alex Howansky