Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diff_match_patch: Generating side-by-side view

Tags:

java

diff

I'm using google-diff-match-patch with my Java app to create a diff. I use the method diff_prettyHtml for generating HTML output of the diff.

However, I would like to have two different outputs, so I can put them side-by-side to make it a bit more easy for the user to see the differences. (For example, like Eclipse does.)

Is there anything in that library I can use to achieve this? How would you do that? (I would not use a different library, if possible.)

like image 837
paoloP Avatar asked Jun 02 '11 08:06

paoloP


2 Answers

Assuming you're not attempting to diff HTML, in which case I'd suggest using DaisyDiff, what you probably want to do with diff-match-patch is line differencing, which is described on a project wiki page. Basically it involves generating an array of hash codes, one for each line of the left and right, and keeping track of those hash codes relative to the lines in a map, and then running those arrays through the diffing algorithm. Then you use the diff output in conjunction with the map to rehydrate left and right highlighting as appropriate.

like image 124
orangepips Avatar answered Oct 04 '22 03:10

orangepips


I have tried to implement a different approach in Python:

http://code.activestate.com/recipes/577784-line-based-side-by-side-diff/

Failing test cases are welcome.

like image 22
cburgmer Avatar answered Oct 04 '22 04:10

cburgmer