cfdiff

Quick Start

  1. There's no ZIP/TAR archive of the project, so you'll need to download each of the files individually from the cfdiff Google Code repository. See the next section for a list of what each of the files do.
  2. Copy at least the diff.cfc file to your CFC area.
  3. Write some code that does something like this:
    <cfset Differ = CreateObject("component", "org.rickosborne.diff")>
    <cfset LeftFile = ListToArray("a,b,c,d,e,f,g")>
    <cfset RightFile = ListToArray("a,d,e,1,2,f,g,h")>
    <cfset Difference = Differ.DiffArrays(LeftFile, RightFile)>
    <cfset Pretty = Differ.Parallelize(Difference, LeftFile, RightFile)>
    If you chose the lazy option from the previous list, your call to create the CFC will look like this:
    <cfset Differ=CreateObject("component","diff")>
    If you chose the third option, then I presume you can figure out how to create the object.
  4. That last variable, Pretty, is the one you'll want to dump or loop over or whatever. If you prefer a unified diff instead of parallel, you can use UnifiedDiffArrays() instead of Parallelize() with the same arguments.

Files

File Purpose Final Location
cfdiff.cssExample stylesheet for the SVN browser.SVN Browser root.
diff.cfcThe main component that does all of the work.See above. Maybe web root, maybe not.
difftest.cfcUnit tests for the diff.cfc file.Not required.
svn.cfmBasic SVN browser front-end.Web root?
svnbrowser.cfcBack-end for the SVN browser that interfaces with the JavaSVN API.See above. Maybe web root, maybe not.
testdiff.cfmUsed to run the unit tests for diff.cfc.Not required.
6 files.

Implementation Details

If you want to use the SVN Browser, you'll need to install the TMate JavaSVN library. If you just want to run diffs, you do not need this library.

Look at svn.cfm for the easiest way to show a diff. It's going to look something like this:

<cfloop query="Pretty">
	<tr>
		<td><cfif IsNumeric(AtFirst)>#NumberFormat(AtFirst)#<cfelse>&nbsp;</cfif></td>
		<td><cfif Len(ValueFirst) GT 0>#Replace(HTMLEditFormat(ValueFirst),Chr(9),"&nbsp;&nbsp;&nbsp;","ALL")#<cfelse>&nbsp;</cfif></td>
		<td><cfif IsNumeric(AtSecond)>#NumberFormat(AtSecond)#<cfelse>&nbsp;</cfif></td>
		<td><cfif Len(ValueSecond) GT 0>#Replace(HTMLEditFormat(ValueSecond),Chr(9),"&nbsp;&nbsp;&nbsp;","ALL")#<cfelse>&nbsp;</cfif></td>
	</tr>
</cfloop>

If you decide you'd prefer to work with the raw difference, that's what that intermediate Difference variable is. Go to town.

License

This code is licensed under the Mozilla Public License (MPL) version 1.1. Read the license before you use the code!

Version / About

Original ColdFusion code by Rick Osborne, 2006. The code includes an algorithm translated from the C-Sharp source by Matthias Hertel, which itself was originally released under the Creative Commons Attribution 2.0 Germany license and is based on a paper by Eugene Meyers in Algorithmica Vol. 1 No. 2, 1986, p 251: "An O(ND) Difference Algorithm and its Variations".