PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Text » Text_Diff » Bug #6251

Unified diffs get too much trailing context

Details

Submitted2005-12-15 17:45 UTC
Frommb at computer-leipzig dot com
Assignedyunosh
StatusClosed
PackageText_Diff
PHP VersionIrrelevant
OSIrrelevant
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