Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.2

Bug #6251 Unified diffs get too much trailing context
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)    

 [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 Test script: --------------- <?php // run me from the commandline // uncomment the following line to try it with xdiff //dl(''); 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("", "\nModified Text\n\n\n\nss\nttt\n"); $o = explode("\n", file_get_contents("dt.orig")); $n = explode("\n", file_get_contents("")); $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'); Expected result: ---------------- @@ -1,5 +1,5 @@ -Original Text +Modified Text Actual result: -------------- @@ -1,7 +1,7 @@ -Original Text +Modified Text ss ttt


 [2005-12-16 11:08 UTC] yunosh
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.