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

Request #5373 Engine that handles existing diffs/patches
Submitted: 2005-09-12 16:07 UTC Modified: 2006-12-17 11:11 UTC
From: o dot persson at gmail dot com Assigned: yunosh
Status: Closed Package: Text_Diff
PHP Version: 5.1.0 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2005-09-12 16:07 UTC] o dot persson at gmail dot com
Description: ------------ Would be really nice to be able to pass an existing diff and take benefit from the rendering functionality offered by this package. I use this myself to parse the output from svn diff. This is the dummy engine I use -- this could probably be solved in a better way. To use this class, ATM you need to explicitly instantiate the class: <?php $diff = file_get_contents('Text/Diff.php.patch'); $renderer = new Text_Diff_Renderer_inline(); $engine = new Text_Diff_Engine_string_diff($diff); echo $renderer->render($engine); ?> Test script: --------------- class Text_Diff_Engine_string_diff extends Text_Diff { function __construct($diff, $dummy = false) { if ($dummy == false) $this->_edits = $this->diff($diff); } function diff($diff, $dummy = null) { $diff = explode("\n", $diff); $edits = array(); foreach ($diff as $line) { switch ($line[0]) { case ' ': $edits[] = &new Text_Diff_Op_copy(array(substr($line, 1))); break; case '+': $edits[] = &new Text_Diff_Op_add(array(substr($line, 1))); break; case '-': $edits[] = &new Text_Diff_Op_delete(array(substr($line, 1))); break; } } return $edits; } }

Comments

 [2005-10-24 11:37 UTC] yunosh
This engine only deals with unified diffs at the moment. Any chance you can extend it to at least support context diffs and perhaps automatically detect the diff format?
 [2005-12-16 06:16 UTC] yunosh
Hello?
 [2005-12-27 17:34 UTC] yunosh
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net 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.