mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 06:20:46 +02:00
updates for the updater and the diff engine.
- this update also includes an important change for including the diff engine, since we may need to include an updated engine before updating. This basically means that for a future update (B4 to another version) requires copying the new diff files first... the new include method should prevent this needed handwork for later versions then. git-svn-id: file:///svn/phpbb/trunk@6695 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -15,10 +15,6 @@ if (!defined('IN_PHPBB'))
|
||||
exit;
|
||||
}
|
||||
|
||||
// Include renderer and engine
|
||||
include_once($phpbb_root_path . 'includes/diff/engine.' . $phpEx);
|
||||
include_once($phpbb_root_path . 'includes/diff/renderer.' . $phpEx);
|
||||
|
||||
/**
|
||||
* Code from pear.php.net, Text_Diff-0.2.1 (beta) package
|
||||
* http://pear.php.net/package/Text_Diff/
|
||||
@@ -46,14 +42,10 @@ class diff
|
||||
* @param array $from_lines An array of strings. Typically these are lines from a file.
|
||||
* @param array $to_lines An array of strings.
|
||||
*/
|
||||
function diff(&$from_content, &$to_content)
|
||||
function diff(&$from_content, &$to_content, $preserve_cr = true)
|
||||
{
|
||||
$diff_engine = &new diff_engine();
|
||||
|
||||
$from_content = preg_replace('#[\n\r]+#', "\n", $from_content);
|
||||
$to_content = preg_replace('#[\n\r]+#', "\n", $to_content);
|
||||
|
||||
$this->_edits = call_user_func_array(array($diff_engine, 'diff'), array(explode("\n", $from_content), explode("\n", $to_content)));
|
||||
$this->_edits = $diff_engine->diff($from_content, $to_content, $preserve_cr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +244,7 @@ class mapped_diff extends diff
|
||||
* compared when computing the diff.
|
||||
* @param array $mapped_to_lines This array should have the same number of elements as $to_lines.
|
||||
*/
|
||||
function mapped_diff($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
|
||||
function mapped_diff(&$from_lines, &$to_lines, &$mapped_from_lines, &$mapped_to_lines)
|
||||
{
|
||||
if (sizeof($from_lines) != sizeof($mapped_from_lines) || sizeof($to_lines) != sizeof($mapped_to_lines))
|
||||
{
|
||||
@@ -418,10 +410,16 @@ class diff3 extends diff
|
||||
* @param array $final1 The first version to compare to.
|
||||
* @param array $final2 The second version to compare to.
|
||||
*/
|
||||
function diff3($orig, $final1, $final2)
|
||||
function diff3(&$orig, &$final1, &$final2)
|
||||
{
|
||||
$engine = new diff_engine();
|
||||
$this->_edits = $this->_diff3($engine->diff($orig, $final1), $engine->diff($orig, $final2));
|
||||
$diff_engine = &new diff_engine();
|
||||
|
||||
$diff_1 = $diff_engine->diff($orig, $final1);
|
||||
$diff_2 = $diff_engine->diff($orig, $final2);
|
||||
|
||||
unset($engine);
|
||||
|
||||
$this->_edits = $this->_diff3($diff_1, $diff_2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -546,7 +544,7 @@ class diff3 extends diff
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
function _diff3($edits1, $edits2)
|
||||
function _diff3(&$edits1, &$edits2)
|
||||
{
|
||||
$edits = array();
|
||||
$bb = &new diff3_block_builder();
|
||||
|
@@ -47,11 +47,32 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
class diff_engine
|
||||
{
|
||||
function diff($from_lines, $to_lines)
|
||||
function diff(&$from_lines, &$to_lines, $preserve_cr = true)
|
||||
{
|
||||
// Remove empty lines...
|
||||
// array_walk($from_lines, array('diff', 'trim_newlines'));
|
||||
// array_walk($to_lines, array('diff', 'trim_newlines'));
|
||||
// If preserve_cr is true, we basically only change \r\n and bare \r to \n to get the same carriage returns for both files
|
||||
// If it is false, we try to only use \n once per line and ommit all empty lines to be able to get a proper data diff
|
||||
|
||||
if (is_array($from_lines))
|
||||
{
|
||||
$from_lines = implode("\n", $from_lines);
|
||||
}
|
||||
|
||||
if (is_array($to_lines))
|
||||
{
|
||||
$to_lines = implode("\n", $to_lines);
|
||||
}
|
||||
|
||||
if ($preserve_cr)
|
||||
{
|
||||
$from_lines = explode("\n", str_replace("\r", "\n", str_replace("\r\n", "\n", $from_lines)));
|
||||
$to_lines = explode("\n", str_replace("\r", "\n", str_replace("\r\n", "\n", $to_lines)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$from_lines = explode("\n", preg_replace('#[\n\r]+#', "\n", $from_lines));
|
||||
$to_lines = explode("\n", preg_replace('#[\n\r]+#', "\n", $to_lines));
|
||||
}
|
||||
|
||||
$n_from = sizeof($from_lines);
|
||||
$n_to = sizeof($to_lines);
|
||||
|
@@ -98,15 +98,20 @@ class diff_renderer
|
||||
if (is_a($diff, 'diff3'))
|
||||
{
|
||||
$diff3 = &$diff;
|
||||
$diff = &new diff($diff3->get_original(), $diff3->merged_output());
|
||||
|
||||
$diff_1 = $diff3->get_original();
|
||||
$diff_2 = $diff3->merged_output();
|
||||
|
||||
unset($diff3);
|
||||
|
||||
$diff = &new diff($diff_1, $diff_2);
|
||||
}
|
||||
|
||||
$nlead = $this->_leading_context_lines;
|
||||
$ntrail = $this->_trailing_context_lines;
|
||||
|
||||
$output = $this->_start_diff();
|
||||
$diffs = $diff->get_diff();
|
||||
$diffs = &$diff->get_diff();
|
||||
|
||||
foreach ($diffs as $i => $edit)
|
||||
{
|
||||
@@ -440,7 +445,11 @@ class diff_renderer_inline extends diff_renderer
|
||||
|
||||
// We want to split on word boundaries, but we need to preserve whitespace as well.
|
||||
// Therefore we split on words, but include all blocks of whitespace in the wordlist.
|
||||
$diff = &new diff($this->_split_on_words($text1, $nl), $this->_split_on_words($text2, $nl));
|
||||
$splitted_text_1 = $this->_split_on_words($text1, $nl);
|
||||
$splitted_text_2 = $this->_split_on_words($text2, $nl);
|
||||
|
||||
$diff = &new diff($splitted_text_1, $splitted_text_2);
|
||||
unset($splitted_text_1, $splitted_text_2);
|
||||
|
||||
// Get the diff in inline format.
|
||||
$renderer = &new diff_renderer_inline(array_merge($this->get_params(), array('split_level' => 'words')));
|
||||
|
Reference in New Issue
Block a user