Home » Text » Text_Diff » Bug #6251
Unified diffs get too much trailing context
Details
| Submitted | 2005-12-15 17:45 UTC |
|---|---|
| From | mb at computer-leipzig dot com |
| Assigned | yunosh |
| Status | Closed |
| Package | Text_Diff |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-12-15 17:45 UTC] mb at computer-leipzig dot com
Description:
------------
This bug is present in Version 0.1.1 of Text_Diff, more exactly in its diff Renderer (and likely also in earlier versions).
Wether the xdiff PECL extension is loaded or not - too much trailing context is added to the generated unified diff hunks.
A patch to fix this is available from
http://www.computer-leipzig.com/~mb/Text_Diff/
Test script:
---------------
<?php // run me from the commandline
// uncomment the following line to try it with xdiff
//dl('xdiff.so');
require_once 'Text/Diff.php';
require_once 'Text/Diff/Renderer.php';
require_once 'Text/Diff/Renderer/unified.php';
// i don't use php5
function my_file_put_contents($filename, $contents)
{ $h = fopen($filename, 'w'); fwrite($h, $contents); fclose($h); }
my_file_put_contents("dt.orig", "\nOriginal Text\n\n\n\nss\nttt\n");
my_file_put_contents("dt.new", "\nModified Text\n\n\n\nss\nttt\n");
$o = explode("\n", file_get_contents("dt.orig"));
$n = explode("\n", file_get_contents("dt.new"));
$diffobj = new Text_Diff($o, $n);
$renderer = new Text_Diff_Renderer_unified(
array(leading_context_lines=>3, trailing_context_lines=>3));
echo $renderer->render($diffobj);
// baseline :)
//system('diff -u dt.orig dt.new');
Expected result:
----------------
@@ -1,5 +1,5 @@
-Original Text
+Modified Text
Actual result:
--------------
@@ -1,7 +1,7 @@
-Original Text
+Modified Text
ss
ttt