00096: Dirty diff result using phpdiff.php of PmWiki-1.0.11

Summary: Dirty diff result using phpdiff.php of PmWiki-1.0.11
Created: 2004-10-16 05:50
Status: Closed - changed for 2.0.devel15 and 1.0.12
Category: Feature
Assigned:
Priority: 3
Version: 1.0.11
OS: ALL

Description: This phpdiff.php function make empty lines to be compared either, thus may give out dirty diff result. Following is an example:

Old text is:

 
title

----

subtitle1

text1

----

subtitle2

text2 

And new text is:

 
title

----

new subtitle

new text

----

subtitle1

text1

----

subtitle2

text2

Then the phpdiff function give diff result like:

 
Changed line 5 from:
subtitle1 
to:
new subtitle 
Changed line 7 from:
text1 
to:
new text 
Changed line 11 from:
subtitle2 
to:
subtitle1 
Changed lines 13-19 from:
text2 
to:
text1 


--------------------------------------------------------------------------------


subtitle2 

text2 

My patch for this is just simply make phpdiff function not to compare empty lines.

I add such lines after the line 50 of the phpdiff.php file:

 
	   if ($t1[$s1]=='' || $t2[$s2]=='')
	     { $s1++; $s2++; continue; }


Agreed, except that the above patch is a little too aggressive about avoiding matches--i.e., if $t2[$s2] is blank then it doesn't even consider if $t1[$s1] might be a worthwhile (non-blank) match and the shortest distance.

I've implemented the above scheme differently--by simply not including blank lines as valid targets for the shortest-distance search (i.e., don't include them in the reverse-index array in the first place).

Thanks for the excellent analysis and suggestion! --Pm