From 38c4bcad55ce1e8203e5507b6db2700120688aae Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 18 Sep 2009 18:18:54 +0000 Subject: Ok, after 20+ hours i think i fixed all grave issues with the updater - smaller memory footprint - better checks for already updated files - even less conflicts - fixed automatic conflict resolving after successful merges - no more conflicts for $Id$ changes - fixed skip_whitespace_changes bug where code blocks were added to diff_op_add whereby the previous or next diff_op_copy already had the change - correctly display merged files in diff view (previously it happened that the old file was used for comparision, although the new file was different/newer/merged) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10163 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/install/install_update.php | 196 +++++++++++++++++++++------------------ 1 file changed, 106 insertions(+), 90 deletions(-) (limited to 'phpBB/install/install_update.php') diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index ad72652e97..3c16a2e82b 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -687,7 +687,7 @@ class install_update extends module default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); - $contents = implode("\n", $diff->merged_new_output()); + $contents = implode("\n", $diff->merged_output()); unset($diff); break; } @@ -1104,24 +1104,6 @@ class install_update extends module break; -/* - $diff = $this->return_diff($this->old_location . $original_file, $phpbb_root_path . $file, $this->new_location . $original_file); - - $tmp = array( - 'file1' => array(), - 'file2' => ($option == MERGE_NEW_FILE) ? implode("\n", $diff->merged_new_output()) : implode("\n", $diff->merged_orig_output()), - ); - - $diff = new diff($tmp['file1'], $tmp['file2']); - - unset($tmp); - - $template->assign_var('S_DIFF_NEW_FILE', true); - $diff_mode = 'inline'; - $this->page_title = 'VIEWING_FILE_CONTENTS'; - - break; -*/ // Merge differences and use new phpBB code for conflicted blocks case MERGE_NEW_FILE: case MERGE_MOD_FILE: @@ -1175,6 +1157,7 @@ class install_update extends module default: $diff = $this->return_diff($this->old_location . $original_file, $phpbb_root_path . $original_file, $this->new_location . $file); + $diff = $this->return_diff($phpbb_root_path . $file, $diff->merged_output()); break; } break; @@ -1362,6 +1345,9 @@ class install_update extends module $update_ary['original'] = $original_file; } + // we only want to know if the files are successfully merged and newlines could result in errors (duplicate addition of lines and such things) + // Therefore we check for empty diffs with two methods, preserving newlines and not preserving them (which mostly works best, therefore the first option) + // On a successfull update the new location file exists but the old one does not exist. // Check for this circumstance, the new file need to be up-to-date with the current file then... if (!file_exists($this->old_location . $original_file) && file_exists($this->new_location . $original_file) && file_exists($phpbb_root_path . $file)) @@ -1401,104 +1387,134 @@ class install_update extends module trigger_error($user->lang['INCOMPLETE_UPDATE_FILES'], E_USER_ERROR); } - $tmp = array( - 'file1' => file_get_contents($this->old_location . $original_file), - 'file2' => file_get_contents($phpbb_root_path . $file), - ); + $preserve_cr_ary = array(false, true); + + foreach ($preserve_cr_ary as $preserve_cr) + { + $tmp = array( + 'file1' => file_get_contents($this->old_location . $original_file), + 'file2' => file_get_contents($phpbb_root_path . $file), + ); + + // We need to diff the contents here to make sure the file is really the one we expect + $diff = new diff($tmp['file1'], $tmp['file2'], $preserve_cr); + $empty_1 = $diff->is_empty(); + + unset($tmp, $diff); + + $tmp = array( + 'file1' => file_get_contents($this->new_location . $original_file), + 'file2' => file_get_contents($phpbb_root_path . $file), + ); - // We need to diff the contents here to make sure the file is really the one we expect - $diff = new diff($tmp['file1'], $tmp['file2'], false); - $empty_1 = $diff->is_empty(); + $diff = new diff($tmp['file1'], $tmp['file2'], $preserve_cr); + $empty_2 = $diff->is_empty(); - unset($tmp, $diff); + unset($tmp, $diff); - $tmp = array( - 'file1' => file_get_contents($this->new_location . $original_file), - 'file2' => file_get_contents($phpbb_root_path . $file), - ); + // If the file is not modified we are finished here... + if ($empty_1) + { + // Further check if it is already up to date - it could happen that non-modified files + // slip through + if ($empty_2) + { + $update_list['up_to_date'][] = $update_ary; + return; + } - // We need to diff the contents here to make sure the file is really the one we expect - $diff = new diff($tmp['file1'], $tmp['file2'], false); - $empty_2 = $diff->is_empty(); + $update_list['not_modified'][] = $update_ary; + return; + } - unset($tmp, $diff); + // If the file had been modified then we need to check if it is already up to date - // If the file is not modified we are finished here... - if ($empty_1) - { - // Further check if it is already up to date - it could happen that non-modified files - // slip through + // if there are no differences we have an up-to-date file... if ($empty_2) { $update_list['up_to_date'][] = $update_ary; return; } - - $update_list['not_modified'][] = $update_ary; - return; } - // If the file had been modified then we need to check if it is already up to date + $conflicts = false; - // if there are no differences we have an up-to-date file... - if ($empty_2) + foreach ($preserve_cr_ary as $preserve_cr) { - $update_list['up_to_date'][] = $update_ary; - return; - } + // if the file is modified we try to make sure a merge succeed + $tmp = array( + 'orig' => file_get_contents($this->old_location . $original_file), + 'final1' => file_get_contents($phpbb_root_path . $file), + 'final2' => file_get_contents($this->new_location . $original_file), + ); - // if the file is modified we try to make sure a merge succeed - $tmp = array( - 'file1' => file_get_contents($this->old_location . $original_file), - 'file2' => file_get_contents($phpbb_root_path . $file), - 'file3' => file_get_contents($this->new_location . $original_file), - ); + $diff = new diff3($tmp['orig'], $tmp['final1'], $tmp['final2'], $preserve_cr); + unset($tmp); - $diff = new diff3($tmp['file1'], $tmp['file2'], $tmp['file3'], false); + if (!$diff->get_num_conflicts()) + { + $tmp = array( + 'file1' => file_get_contents($phpbb_root_path . $file), + 'file2' => implode("\n", $diff->merged_output()), + ); - unset($tmp); + // now compare the merged output with the original file to see if the modified file is up to date + $diff2 = new diff($tmp['file1'], $tmp['file2'], $preserve_cr); + $empty = $diff2->is_empty(); - if ($diff->get_num_conflicts()) - { - $update_ary['conflicts'] = $diff->get_num_conflicts(); + unset($diff, $diff2); - // There is one special case... users having merged with a conflicting file... we need to check this - $tmp = array( - 'file1' => file_get_contents($phpbb_root_path . $file), - 'file2' => implode("\n", $diff->merged_orig_output()), - ); + if ($empty) + { + $update_list['up_to_date'][] = $update_ary; + return; + } + } + else + { + // There is one special case... users having merged with a conflicting file... we need to check this + $tmp = array( + 'file1' => file_get_contents($phpbb_root_path . $file), + 'file2' => implode("\n", $diff->merged_new_output()), + ); - $diff = new diff($tmp['file1'], $tmp['file2'], false); - $empty = $diff->is_empty(); + $diff2 = new diff($tmp['file1'], $tmp['file2'], $preserve_cr); + $empty = $diff2->is_empty(); - if ($empty) - { - unset($update_ary['conflicts']); - unset($diff); - $update_list['up_to_date'][] = $update_ary; - return; - } + if (!$empty) + { + unset($tmp, $diff2); - $update_list['conflict'][] = $update_ary; - unset($diff); + // We check if the user merged with his output + $tmp = array( + 'file1' => file_get_contents($phpbb_root_path . $file), + 'file2' => implode("\n", $diff->merged_orig_output()), + ); - return; - } + $diff2 = new diff($tmp['file1'], $tmp['file2'], $preserve_cr); + $empty = $diff2->is_empty(); + } - $tmp = array( - 'file1' => file_get_contents($phpbb_root_path . $file), - 'file2' => implode("\n", $diff->merged_new_output()), - ); + if (!$empty) + { + $conflicts = $diff->get_num_conflicts(); + } - // now compare the merged output with the original file to see if the modified file is up to date - $diff = new diff($tmp['file1'], $tmp['file2'], false); - $empty = $diff->is_empty(); + unset($diff, $diff2); - if ($empty) - { - unset($diff); + if ($empty) + { + // A conflict got resolved... + $update_list['up_to_date'][] = $update_ary; + return; + } + } + } - $update_list['up_to_date'][] = $update_ary; + if ($conflicts !== false) + { + $update_ary['conflicts'] = $conflicts; + $update_list['conflict'][] = $update_ary; return; } @@ -1650,7 +1666,7 @@ class install_update extends module /** * Wrapper for returning a diff object */ - function &return_diff() + function return_diff() { $args = func_get_args(); $three_way_diff = (func_num_args() > 2) ? true : false; -- cgit v1.2.1 From 7a244e1d2bd62f87d678c754b0890fb7ac379673 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 20 Sep 2009 16:18:41 +0000 Subject: if preserve_cr is true and the file generated no conflict but is obviously not "empty" we tag it as modified because preserve_cr is the default mode for showing modifications (else the user gets a resolvable conflict and may wonder why ;)) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10167 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/install/install_update.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/install/install_update.php') diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 3c16a2e82b..ab7ec35705 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -1469,6 +1469,13 @@ class install_update extends module $update_list['up_to_date'][] = $update_ary; return; } + + // If we preserve cr tag it as modified because the conflict would not show in this mode anyway + if ($preserve_cr) + { + $update_list['modified'][] = $update_ary; + return; + } } else { -- cgit v1.2.1