4

I'm writing a web app that needs many users to work on the same contents. So there's high probability that one user overwrites another user's changes du to a race condition.

Ruby on Rails provides an easy mechanism to prevent this, which is called optimistic locking. But it only prevents saving when an overwrite would happen, it doesn't help a lot merging those changes.

So whenever Rails fires a StaleObject exception, I re-display the form with a warning:


(source: snag.gy)

I'm using the diffy gem to display the changes.

This works pretty nice, but the Difference isn't optimised yet: while one-liner (<input type="text">) fields are diffed pretty nicely (diff by word), many-liner fields (<textarea>) don't give very sophisticated clues about the changes (diff by sentence).

I know from GitHub much more sophisticated diffs (and as a versioning tool, I think git has a lot more possibilities to identify changes and compare them in a human readable way):

But also Stack Overflow has great diffs:

So: what mechanism does Stack Overflow use to provide these fine grained diffs? A normal diff call on the command line? Some more sophisticated tool like git or something?

It seems that diffing a many-lines text includes at least these steps:

  1. Diff by line, so changed lines are detected
  2. Diff changed lines by word, to find the fine-grained changes
  3. Display only changed lines (with some context lines, if needed), diffed by word
2

0

You must log in to answer this question.

Browse other questions tagged .