Source for file Diff3.php
Documentation is available at Diff3.php
require_once 'Text/Diff.php';
* A class for computing three way diffs.
* $Horde: framework/Text_Diff/Diff3.php,v 1.3 2005/06/23 19:40:18 selsky Exp $
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
var $_conflictingBlocks = 0;
* Computes diff between 3 sequences of strings.
* @param array $orig The original lines to use.
* @param array $final1 The first version to compare to.
* @param array $final2 The second version to compare to.
$engine = &new Text_Diff_Engine_xdiff ();
$engine = &new Text_Diff_Engine_native ();
$this->_edits = $this->_diff3 ($engine->diff ($orig, $final1),
$engine->diff ($orig, $final2));
foreach ($this->_edits as $edit) {
if ($edit->isConflict ()) {
/* FIXME: this should probably be moved somewhere else. */
array ('<<<<<<<' . ($label1 ? ' ' . $label1 : '')),
array ('>>>>>>>' . ($label2 ? ' ' . $label2 : '')));
$this->_conflictingBlocks++;
function _diff3 ($edits1, $edits2)
$bb = &new Text_Diff3_BlockBuilder ();
if ($e1 && $e2 && is_a($e1, 'Text_Diff_Op_copy') && is_a($e2, 'Text_Diff_Op_copy')) {
/* We have copy blocks from both diffs. This is the (only)
* time we want to emit a diff3 copy block. Flush current
* diff3 diff block, if any. */
if ($edit = $bb->finish ()) {
$ncopy = min($e1->norig (), $e2->norig ());
$edits[] = &new Text_Diff3_Op_copy (array_slice($e1->orig , 0 , $ncopy));
if ($e1->norig () > $ncopy) {
if ($e2->norig () > $ncopy) {
if ($e1->orig && $e2->orig ) {
$norig = min($e1->norig (), $e2->norig ());
if (is_a($e1, 'Text_Diff_Op_copy')) {
if (is_a($e2, 'Text_Diff_Op_copy')) {
if ($e1 && ! $e1->orig ) {
if ($e2 && ! $e2->orig ) {
if ($edit = $bb->finish ()) {
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
function Text_Diff3_Op ($orig = false , $final1 = false , $final2 = false )
$this->orig = $orig ? $orig : array ();
$this->final1 = $final1 ? $final1 : array ();
$this->final2 = $final2 ? $final2 : array ();
if (!isset ($this->_merged)) {
if ($this->final1 === $this->final2) {
$this->_merged = &$this->final1;
} elseif ($this->final1 === $this->orig) {
$this->_merged = &$this->final2;
} elseif ($this->final2 === $this->orig) {
$this->_merged = &$this->final1;
return $this->merged () === false;
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
class Text_Diff3_Op_copy extends Text_Diff3_Op {
function Text_Diff3_Op_Copy ($lines = false )
$this->orig = $lines ? $lines : array ();
$this->final1 = &$this->orig;
$this->final2 = &$this->orig;
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
class Text_Diff3_BlockBuilder {
function Text_Diff3_BlockBuilder ()
$this->_append ($this->orig, $lines);
$this->_append ($this->final1, $lines);
$this->_append ($this->final2, $lines);
return !$this->orig && !$this->final1 && !$this->final2;
$edit = &new Text_Diff3_Op ($this->orig, $this->final1, $this->final2);
$this->orig = $this->final1 = $this->final2 = array ();
function _append (&$array, $lines)
Documentation generated on Mon, 11 Mar 2019 14:16:38 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|