Wanted: PHP Implementation of Unified Diff

Sebastian Bergmann » 28 July 2007 » in PHPUnit » 9 Comments

For PHPUnit I need a PHP function (written in PHP, an extension would not solve the problem) that
  • takes two strings as its input and
  • returns a string with the differences between the two string in the same format as GNU diff would return for diff -u for two files that contain the respective strings.

    Currently I rely on GNU diff being installed on the system that PHPUnit runs on. This thread on the PHPUnit mailinglist shows that this poses a problem.

    I know that there is a Text_Diff package in PEAR but it does way more than I need.
Defined tags for this entry: , ,

Trackback specific URI for this entry

9 Comments to "Wanted: PHP Implementation of Unified Diff"

Display comments as (Linear | Threaded)
  1. moshe Weitzman
    28/07/2007 at 14:06 Permalink
    drupal's diff module uses some code developed for phpwiki. see http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/diff/DiffEngine.php

    Reply

  2. Sebastian
    28/07/2007 at 15:46 Permalink
    Any preferred license?

    Reply

  3. Sebastian Bergmann
    28/07/2007 at 16:27 Permalink
    BSD License

    Reply

  4. Jan Schneider
    28/07/2007 at 19:04 Permalink
    Why don't pick the pieces from Text_Diff that you need, if the whole package offers too much for you?

    Reply

  5. Sebastian Bergmann
    28/07/2007 at 19:43 Permalink
    Can I take the pieces I need and add them to the PHPUnit codebase (while keeping authorship/copyright information)? Are the LGPL and BSD License compatible for this?

    Reply

  6. ensi
    30/07/2007 at 09:28 Permalink
    Maybe this will do the job?

    http://www.holomind.de/phpnet/diff2.src.php

    Reply

  7. Clay Loveless
    30/07/2007 at 20:07 Permalink
    @ensi: GPL != BSD

    @Sebastian: Glad you posted this request. I'm interested in the same thing.

    Reply

  8. Justin Patrin
    30/07/2007 at 22:03 Permalink
    What is wrong with Text_Diff? It has a unified diff renderer that works just fine. Any diff code would have to do the same general workt hat Text_Diff does to find the diffs and then render into your preferred format.

    Reply

  9. Schmalls
    01/08/2007 at 04:09 Permalink
    I put together a BSD diff and patch function and posted it here: http://pastebin.com/f145611b3

    I haven't tested how fast it is (probably slow right now), and it doesn't print a unified diff (but that shouldn't be too hard to implement) but prints out a modified original diff for space efficiency.

    Reply

0 Trackbacks to "Wanted: PHP Implementation of Unified Diff"

  1. No Trackbacks

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.