diff --git a/main/inc/lib/pear/Text/Diff.php b/main/inc/lib/pear/Text/Diff.php index f8a974c1c0..86d7aee82a 100644 --- a/main/inc/lib/pear/Text/Diff.php +++ b/main/inc/lib/pear/Text/Diff.php @@ -6,7 +6,7 @@ * The original PHP version of this code was written by Geoffrey T. Dairiki * , and is used/adapted with his permission. * - * $Horde: framework/Text_Diff/Diff.php,v 1.26 2008/01/04 10:07:49 jan Exp $ + * $Horde: framework/Text_Diff/Diff.php,v 1.11.2.11 2008/02/24 10:57:46 jan Exp $ * * Copyright 2004 Geoffrey T. Dairiki * Copyright 2004-2008 The Horde Project (http://www.horde.org/) @@ -63,6 +63,46 @@ class Text_Diff { { return $this->_edits; } + + /** + * returns the number of new (added) lines in a given diff. + * + * @since Text_Diff 1.1.0 + * @since Horde 3.2 + * + * @return integer The number of new lines + */ + function countAddedLines() + { + $count = 0; + foreach ($this->_edits as $edit) { + if (is_a($edit, 'Text_Diff_Op_add') || + is_a($edit, 'Text_Diff_Op_change')) { + $count += $edit->nfinal(); + } + } + return $count; + } + + /** + * Returns the number of deleted (removed) lines in a given diff. + * + * @since Text_Diff 1.1.0 + * @since Horde 3.2 + * + * @return integer The number of deleted lines + */ + function countDeletedLines() + { + $count = 0; + foreach ($this->_edits as $edit) { + if (is_a($edit, 'Text_Diff_Op_delete') || + is_a($edit, 'Text_Diff_Op_change')) { + $count += $edit->norig(); + } + } + return $count; + } /** * Computes a reversed diff. diff --git a/main/inc/lib/pear/Text/Diff/Engine/native.php b/main/inc/lib/pear/Text/Diff/Engine/native.php index aa5bca5b04..60d6805f23 100644 --- a/main/inc/lib/pear/Text/Diff/Engine/native.php +++ b/main/inc/lib/pear/Text/Diff/Engine/native.php @@ -1,9 +1,8 @@ . The original PHP version of this * code was written by him, and is used/adapted with his permission. * + * $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.7.2.4 2008/01/04 10:38:10 jan Exp $ + * * Copyright 2004-2008 The Horde Project (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did diff --git a/main/inc/lib/pear/Text/Diff/Engine/shell.php b/main/inc/lib/pear/Text/Diff/Engine/shell.php index 7e9629f506..1bbb58caaf 100644 --- a/main/inc/lib/pear/Text/Diff/Engine/shell.php +++ b/main/inc/lib/pear/Text/Diff/Engine/shell.php @@ -5,7 +5,7 @@ * This class uses the Unix `diff` program via shell_exec to compute the * differences between the two input arrays. * - * $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.8 2008/01/04 10:07:50 jan Exp $ + * $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.6.2.3 2008/01/04 10:37:27 jan Exp $ * * Copyright 2007-2008 The Horde Project (http://www.horde.org/) * diff --git a/main/inc/lib/pear/Text/Diff/Engine/string.php b/main/inc/lib/pear/Text/Diff/Engine/string.php index 1a0bd3f37f..4b29daafe9 100644 --- a/main/inc/lib/pear/Text/Diff/Engine/string.php +++ b/main/inc/lib/pear/Text/Diff/Engine/string.php @@ -10,7 +10,7 @@ * echo $renderer->render($diff); * * - * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.7 2008/01/04 10:07:50 jan Exp $ + * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.5.2.5 2008/09/10 08:31:58 jan Exp $ * * Copyright 2005 Örjan Persson * Copyright 2005-2008 The Horde Project (http://www.horde.org/) @@ -48,17 +48,20 @@ class Text_Diff_Engine_string { $unified = strpos($diff, '---'); if ($context === $unified) { return PEAR::raiseError('Type of diff could not be detected'); - } elseif ($context === false || $context === false) { + } elseif ($context === false || $unified === false) { $mode = $context !== false ? 'context' : 'unified'; } else { $mode = $context < $unified ? 'context' : 'unified'; } } - // split by new line and remove the diff header + // Split by new line and remove the diff header, if there is one. $diff = explode("\n", $diff); - array_shift($diff); - array_shift($diff); + if (($mode == 'context' && strpos($diff[0], '***') === 0) || + ($mode == 'unified' && strpos($diff[0], '---') === 0)) { + array_shift($diff); + array_shift($diff); + } if ($mode == 'context') { return $this->parseContextDiff($diff); @@ -85,7 +88,7 @@ class Text_Diff_Engine_string { do { $diff1[] = substr($diff[$i], 1); } while (++$i < $end && substr($diff[$i], 0, 1) == ' '); - $edits[] = &new Text_Diff_Op_copy($diff1); + $edits[] = new Text_Diff_Op_copy($diff1); break; case '+': @@ -93,7 +96,7 @@ class Text_Diff_Engine_string { do { $diff1[] = substr($diff[$i], 1); } while (++$i < $end && substr($diff[$i], 0, 1) == '+'); - $edits[] = &new Text_Diff_Op_add($diff1); + $edits[] = new Text_Diff_Op_add($diff1); break; case '-': @@ -107,9 +110,9 @@ class Text_Diff_Engine_string { $diff2[] = substr($diff[$i++], 1); } if (count($diff2) == 0) { - $edits[] = &new Text_Diff_Op_delete($diff1); + $edits[] = new Text_Diff_Op_delete($diff1); } else { - $edits[] = &new Text_Diff_Op_change($diff1, $diff2); + $edits[] = new Text_Diff_Op_change($diff1, $diff2); } break; @@ -175,7 +178,7 @@ class Text_Diff_Engine_string { $array[] = substr($diff[$j++], 2); } if (count($array) > 0) { - $edits[] = &new Text_Diff_Op_copy($array); + $edits[] = new Text_Diff_Op_copy($array); } if ($i < $max_i) { @@ -189,21 +192,21 @@ class Text_Diff_Engine_string { $diff2[] = substr($diff[$j++], 2); } } while (++$i < $max_i && substr($diff[$i], 0, 1) == '!'); - $edits[] = &new Text_Diff_Op_change($diff1, $diff2); + $edits[] = new Text_Diff_Op_change($diff1, $diff2); break; case '+': do { $diff1[] = substr($diff[$i], 2); } while (++$i < $max_i && substr($diff[$i], 0, 1) == '+'); - $edits[] = &new Text_Diff_Op_add($diff1); + $edits[] = new Text_Diff_Op_add($diff1); break; case '-': do { $diff1[] = substr($diff[$i], 2); } while (++$i < $max_i && substr($diff[$i], 0, 1) == '-'); - $edits[] = &new Text_Diff_Op_delete($diff1); + $edits[] = new Text_Diff_Op_delete($diff1); break; } } @@ -215,14 +218,14 @@ class Text_Diff_Engine_string { do { $diff2[] = substr($diff[$j++], 2); } while ($j < $max_j && substr($diff[$j], 0, 1) == '+'); - $edits[] = &new Text_Diff_Op_add($diff2); + $edits[] = new Text_Diff_Op_add($diff2); break; case '-': do { $diff2[] = substr($diff[$j++], 2); } while ($j < $max_j && substr($diff[$j], 0, 1) == '-'); - $edits[] = &new Text_Diff_Op_delete($diff2); + $edits[] = new Text_Diff_Op_delete($diff2); break; } } diff --git a/main/inc/lib/pear/Text/Diff/Engine/xdiff.php b/main/inc/lib/pear/Text/Diff/Engine/xdiff.php index a39a4be176..7ff477edb6 100644 --- a/main/inc/lib/pear/Text/Diff/Engine/xdiff.php +++ b/main/inc/lib/pear/Text/Diff/Engine/xdiff.php @@ -5,7 +5,7 @@ * This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff) * to compute the differences between the two input arrays. * - * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.6 2008/01/04 10:07:50 jan Exp $ + * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.4.2.3 2008/01/04 10:37:27 jan Exp $ * * Copyright 2004-2008 The Horde Project (http://www.horde.org/) * diff --git a/main/inc/lib/pear/Text/Diff/Mapped.php b/main/inc/lib/pear/Text/Diff/Mapped.php index 7feba646be..840375998a 100644 --- a/main/inc/lib/pear/Text/Diff/Mapped.php +++ b/main/inc/lib/pear/Text/Diff/Mapped.php @@ -1,6 +1,6 @@ \n\n"; + exit; +} + +/* Make sure both files exist. */ +if (!is_readable($argv[1])) { + echo "$argv[1] not found or not readable.\n\n"; +} +if (!is_readable($argv[2])) { + echo "$argv[2] not found or not readable.\n\n"; +} + +/* Load the lines of each file. */ +$lines1 = file($argv[1]); +$lines2 = file($argv[2]); + +/* Create the Diff object. */ +$diff = new Text_Diff('auto', array($lines1, $lines2)); + +/* Output the diff in unified format. */ +$renderer = new Text_Diff_Renderer_unified(); +echo $renderer->render($diff); diff --git a/main/inc/lib/pear/Text/tests/1.txt b/main/inc/lib/pear/Text/tests/1.txt new file mode 100644 index 0000000000..976c44755e --- /dev/null +++ b/main/inc/lib/pear/Text/tests/1.txt @@ -0,0 +1,3 @@ +This line is the same. +This line is different in 1.txt +This line is the same. diff --git a/main/inc/lib/pear/Text/tests/2.txt b/main/inc/lib/pear/Text/tests/2.txt new file mode 100644 index 0000000000..6fa8051d9f --- /dev/null +++ b/main/inc/lib/pear/Text/tests/2.txt @@ -0,0 +1,3 @@ +This line is the same. +This line is different in 2.txt +This line is the same. diff --git a/main/inc/lib/pear/Text/tests/3.txt b/main/inc/lib/pear/Text/tests/3.txt new file mode 100644 index 0000000000..0c26fe9872 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/3.txt @@ -0,0 +1,4 @@ +This line is the same. +This line is different in 1.txt +This line is the same. +This line is new in 3.txt diff --git a/main/inc/lib/pear/Text/tests/4.txt b/main/inc/lib/pear/Text/tests/4.txt new file mode 100644 index 0000000000..7cbc69d9ab --- /dev/null +++ b/main/inc/lib/pear/Text/tests/4.txt @@ -0,0 +1,3 @@ +This line is the same. +This line is different in 4.txt +This line is the same. diff --git a/main/inc/lib/pear/Text/tests/5.txt b/main/inc/lib/pear/Text/tests/5.txt new file mode 100644 index 0000000000..d48db2214c --- /dev/null +++ b/main/inc/lib/pear/Text/tests/5.txt @@ -0,0 +1,5 @@ +This is a test. +Adding random text to simulate files. +Various Content. +More Content. +Testing diff and renderer. diff --git a/main/inc/lib/pear/Text/tests/6.txt b/main/inc/lib/pear/Text/tests/6.txt new file mode 100644 index 0000000000..5b421cd3da --- /dev/null +++ b/main/inc/lib/pear/Text/tests/6.txt @@ -0,0 +1,7 @@ +This is a test. +Adding random text to simulate files. +Inserting a line. +Various Content. +Replacing content. +Testing similarities and renderer. +Append content. diff --git a/main/inc/lib/pear/Text/tests/context.patch b/main/inc/lib/pear/Text/tests/context.patch new file mode 100644 index 0000000000..2a4fad9242 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/context.patch @@ -0,0 +1,11 @@ +*** 1.txt 2005-03-21 13:37:59.000000000 +0100 +--- 2.txt 2005-03-21 13:38:00.000000000 +0100 +*************** +*** 1,3 **** + This line is the same. +! This line is different in 1.txt + This line is the same. +--- 1,3 ---- + This line is the same. +! This line is different in 2.txt + This line is the same. diff --git a/main/inc/lib/pear/Text/tests/context.phpt b/main/inc/lib/pear/Text/tests/context.phpt new file mode 100644 index 0000000000..a7a8c93df4 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/context.phpt @@ -0,0 +1,25 @@ +--TEST-- +Text_Diff: Context renderer +--FILE-- +render($diff); +?> +--EXPECT-- +*************** +*** 1,3 **** + This line is the same. +! This line is different in 1.txt + This line is the same. +--- 1,3 ---- + This line is the same. +! This line is different in 2.txt + This line is the same. diff --git a/main/inc/lib/pear/Text/tests/context2.phpt b/main/inc/lib/pear/Text/tests/context2.phpt new file mode 100644 index 0000000000..69f8e0fa8d --- /dev/null +++ b/main/inc/lib/pear/Text/tests/context2.phpt @@ -0,0 +1,31 @@ +--TEST-- +Text_Diff: Context renderer 2 +--FILE-- +render($diff); +?> +--EXPECT-- +*************** +*** 1,5 **** + This is a test. + Adding random text to simulate files. + Various Content. +! More Content. +! Testing diff and renderer. +--- 1,7 ---- + This is a test. + Adding random text to simulate files. ++ Inserting a line. + Various Content. +! Replacing content. +! Testing similarities and renderer. +! Append content. diff --git a/main/inc/lib/pear/Text/tests/diff.phpt b/main/inc/lib/pear/Text/tests/diff.phpt new file mode 100644 index 0000000000..62f6cfb39d --- /dev/null +++ b/main/inc/lib/pear/Text/tests/diff.phpt @@ -0,0 +1,62 @@ +--TEST-- +Text_Diff: Basic diff operation +--FILE-- + +--EXPECT-- +text_diff object +( + [_edits] => array + ( + [0] => text_diff_op_copy object + ( + [orig] => array + ( + [0] => this line is the same. + ) + + [final] => array + ( + [0] => this line is the same. + ) + + ) + + [1] => text_diff_op_change object + ( + [orig] => array + ( + [0] => this line is different in 1.txt + ) + + [final] => array + ( + [0] => this line is different in 2.txt + ) + + ) + + [2] => text_diff_op_copy object + ( + [orig] => array + ( + [0] => this line is the same. + ) + + [final] => array + ( + [0] => this line is the same. + ) + + ) + + ) + +) diff --git a/main/inc/lib/pear/Text/tests/inline.phpt b/main/inc/lib/pear/Text/tests/inline.phpt new file mode 100644 index 0000000000..6a415c0c77 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/inline.phpt @@ -0,0 +1,19 @@ +--TEST-- +Text_Diff: Inline renderer +--FILE-- +render($diff); +?> +--EXPECT-- +This line is the same. +This line is different in 1.txt2.txt +This line is the same. diff --git a/main/inc/lib/pear/Text/tests/inline2.phpt b/main/inc/lib/pear/Text/tests/inline2.phpt new file mode 100644 index 0000000000..c975b70574 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/inline2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Text_Diff: Inline renderer 2 +--FILE-- +render($diff); +?> +--EXPECT-- +This is a test. +Adding random text to simulate files. +Inserting a line. +Various Content. +More Content.Replacing content. +Testing diffsimilarities and renderer. +Append content. diff --git a/main/inc/lib/pear/Text/tests/pear_bug12740.phpt b/main/inc/lib/pear/Text/tests/pear_bug12740.phpt new file mode 100644 index 0000000000..13dc3522ef --- /dev/null +++ b/main/inc/lib/pear/Text/tests/pear_bug12740.phpt @@ -0,0 +1,30 @@ +--TEST-- +Text_Diff: PEAR Bug #12740 (failed assertion) +--FILE-- +The tax credit amounts to 30% of the cost of the system, with a +maximum of 2,000. This credit is separate from the 500 home improvement +credit. +

Fuel Cells
+
  • Your fuel 123456789
  • +QQ; + +$b = << of gas emissions by 2050 +
  • Raise car fuel economy to 50 mpg by 2017
  • +
  • Increase access to mass transit systems
  • +QQ; + +$diff = new Text_Diff(explode("\n", $b), explode("\n", $a)); +$renderer = new Text_Diff_Renderer_inline(); +$renderer->render($diff); + +?> +--EXPECT-- diff --git a/main/inc/lib/pear/Text/tests/pear_bug4879.phpt b/main/inc/lib/pear/Text/tests/pear_bug4879.phpt new file mode 100644 index 0000000000..e5086720a6 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/pear_bug4879.phpt @@ -0,0 +1,30 @@ +--TEST-- +Text_Diff: PEAR Bug #4879 (inline renderer hangs on numbers in input string) +--FILE-- +render($diff); +?> +--EXPECT-- +Common text +Bob had 1 apple,10 apples, Alice had 2.1. +Bon appetit! diff --git a/main/inc/lib/pear/Text/tests/pear_bug6251.phpt b/main/inc/lib/pear/Text/tests/pear_bug6251.phpt new file mode 100644 index 0000000000..bf1101fb9e --- /dev/null +++ b/main/inc/lib/pear/Text/tests/pear_bug6251.phpt @@ -0,0 +1,45 @@ +--TEST-- +Text_Diff: PEAR Bug #6251 (too much trailing context) +--FILE-- + 3, 'trailing_context_lines' => 3)); + +// We need to use var_dump, as the test runner strips trailing empty lines. +var_dump($renderer->render($diff)); +?> +--EXPECT-- +string(54) "@@ -1,5 +1,5 @@ + +-Original Text ++Modified Text + + + +" diff --git a/main/inc/lib/pear/Text/tests/pear_bug6428.phpt b/main/inc/lib/pear/Text/tests/pear_bug6428.phpt new file mode 100644 index 0000000000..9380219632 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/pear_bug6428.phpt @@ -0,0 +1,18 @@ +--TEST-- +Text_Diff: PEAR Bug #6428 (problem with single digits after space) +--FILE-- +render($diff); +?> +--EXPECT-- +Line 1 1 +Another line diff --git a/main/inc/lib/pear/Text/tests/string.phpt b/main/inc/lib/pear/Text/tests/string.phpt new file mode 100644 index 0000000000..900119894c --- /dev/null +++ b/main/inc/lib/pear/Text/tests/string.phpt @@ -0,0 +1,145 @@ +--TEST-- +Text_Diff: Text_Diff_Engine_string test. +--FILE-- +getDiff(), 'PEAR_Error')); +echo "\n"; +$diff_u2 = new Text_Diff('string', array($unified2, 'unified')); +echo strtolower(print_r($diff_u2, true)); + +$context = file_get_contents(dirname(__FILE__) . '/context.patch'); +$diff_c = new Text_Diff('string', array($context)); +echo strtolower(print_r($diff_c, true)); + +?> +--EXPECT-- +text_diff object +( + [_edits] => array + ( + [0] => text_diff_op_copy object + ( + [orig] => array + ( + [0] => this line is the same. + ) + + [final] => array + ( + [0] => this line is the same. + ) + + ) + + [1] => text_diff_op_change object + ( + [orig] => array + ( + [0] => this line is different in 1.txt + ) + + [final] => array + ( + [0] => this line is different in 2.txt + ) + + ) + + [2] => text_diff_op_copy object + ( + [orig] => array + ( + [0] => this line is the same. + ) + + [final] => array + ( + [0] => this line is the same. + ) + + ) + + ) + +) +true +text_diff object +( + [_edits] => array + ( + [0] => text_diff_op_change object + ( + [orig] => array + ( + [0] => for the first time in u.s. history number of private contractors and troops are equal + ) + + [final] => array + ( + [0] => number of private contractors and troops are equal for first time in u.s. history + ) + + ) + + ) + +) +text_diff object +( + [_edits] => array + ( + [0] => text_diff_op_copy object + ( + [orig] => array + ( + [0] => this line is the same. + ) + + [final] => array + ( + [0] => this line is the same. + ) + + ) + + [1] => text_diff_op_change object + ( + [orig] => array + ( + [0] => this line is different in 1.txt + ) + + [final] => array + ( + [0] => this line is different in 2.txt + ) + + ) + + [2] => text_diff_op_copy object + ( + [orig] => array + ( + [0] => this line is the same. + ) + + [final] => array + ( + [0] => this line is the same. + ) + + ) + + ) + +) diff --git a/main/inc/lib/pear/Text/tests/unified.patch b/main/inc/lib/pear/Text/tests/unified.patch new file mode 100644 index 0000000000..b2b3f25806 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/unified.patch @@ -0,0 +1,7 @@ +--- 1.txt 2005-03-21 13:37:59.000000000 +0100 ++++ 2.txt 2005-03-21 13:38:00.000000000 +0100 +@@ -1,3 +1,3 @@ + This line is the same. +-This line is different in 1.txt ++This line is different in 2.txt + This line is the same. diff --git a/main/inc/lib/pear/Text/tests/unified.phpt b/main/inc/lib/pear/Text/tests/unified.phpt new file mode 100644 index 0000000000..0611459184 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/unified.phpt @@ -0,0 +1,21 @@ +--TEST-- +Text_Diff: Unified renderer +--FILE-- +render($diff); +?> +--EXPECT-- +@@ -1,3 +1,3 @@ + This line is the same. +-This line is different in 1.txt ++This line is different in 2.txt + This line is the same. diff --git a/main/inc/lib/pear/Text/tests/unified2.phpt b/main/inc/lib/pear/Text/tests/unified2.phpt new file mode 100644 index 0000000000..0ca5b90ad7 --- /dev/null +++ b/main/inc/lib/pear/Text/tests/unified2.phpt @@ -0,0 +1,26 @@ +--TEST-- +Text_Diff: Unified renderer 2 +--FILE-- +render($diff); +?> +--EXPECT-- +@@ -1,5 +1,7 @@ + This is a test. + Adding random text to simulate files. ++Inserting a line. + Various Content. +-More Content. +-Testing diff and renderer. ++Replacing content. ++Testing similarities and renderer. ++Append content.