devbox@COMPUTEC The Computec development blog

12Jun/090

Using wdiff to show differences between text strings

We're currently in the process of adding some versioning- and history-functions to our ColdFusion-based CMS CBOX. Versioning is completely done on the database layer, thanks to some PostgreSQL database programming with lots of triggers and PL/pgSQL and PL/Perl. I might elaborate on this some other time.

One issue I had was to display the changes between two versions of a text to users. On the database level I actually already use unified diffs for a similar purpose, as I don't want so store a couple of thousand characters which haven't changed at all but for maybe one deleted comma. I'm using some Perl to do the diffing and patching from within PL/pgSQL functions, but you could also try something like cfdiff if you need a pure ColdFusion solution.

A simple diff might look like this:

@@ -1,3 +1 @@
-Article 1
+Article 1 UPDATED
-
-

I find diffs quite hard to read for humans though, especially as they drop at least some context. It might be alright for programmers, but ordinary people expect something more like the "change track" feature from OpenOffice or Word, something that's not line-based, but in fact word-based and displays the full text with the changes marked intuitively inside. This is where wdiff kicks in because it can provide just that.