Changes in trunk/wp-includes/wp-diff.php [17781:19712]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/wp-diff.php
r17781 r19712 203 203 204 204 // Does the aforementioned additional processing 205 // *_matches tell what rows are "the same" in orig and final. 205 // *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes 206 206 // match is numeric: an index in other column 207 // match is 'X': no match. 207 // match is 'X': no match. It is a new row 208 208 // *_rows are column vectors for the orig column and the final column. 209 209 // row >= 0: an indix of the $orig or $final array 210 210 // row < 0: a blank row for that column 211 211 list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final ); 212 213 212 214 213 // These will hold the word changes as determined by an inline diff … … 232 231 $diff_ratio = $stripped_matches / $stripped_diff; 233 232 if ( $diff_ratio > $this->_diff_threshold ) 234 continue; // Too different. 233 continue; // Too different. Don't save diffs. 235 234 } 236 235 … … 242 241 243 242 foreach ( array_keys($orig_rows) as $row ) { 244 // Both columns have blanks. 243 // Both columns have blanks. Ignore them. 245 244 if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) 246 245 continue; 247 246 248 // If we have a word based diff, use it. 247 // If we have a word based diff, use it. Otherwise, use the normal line. 249 248 if ( isset( $orig_diffs[$orig_rows[$row]] ) ) 250 249 $orig_line = $orig_diffs[$orig_rows[$row]]; … … 261 260 $final_line = ''; 262 261 263 if ( $orig_rows[$row] < 0 ) { // Orig is blank. 262 if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row. 264 263 $r .= $this->_added( array($final_line), false ); 265 } elseif ( $final_rows[$row] < 0 ) { // Final is blank. 264 } elseif ( $final_rows[$row] < 0 ) { // Final is blank. This is really a deleted row. 266 265 $r .= $this->_deleted( array($orig_line), false ); 267 266 } else { // A true changed row. … … 289 288 function interleave_changed_lines( $orig, $final ) { 290 289 291 // Contains all pairwise string comparisons. 290 // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array. 292 291 $matches = array(); 293 292 foreach ( array_keys($orig) as $o ) { … … 310 309 continue; 311 310 312 // First match for these guys. 311 // First match for these guys. Must be best match 313 312 if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) { 314 313 $orig_matches[$o] = $f; … … 330 329 ksort($final_matches); 331 330 332 333 331 // Stores rows and blanks for each column. 334 332 $orig_rows = $orig_rows_copy = array_keys($orig_matches); … … 343 341 if ( false === $final_pos ) { // This orig is paired with a blank final. 344 342 array_splice( $final_rows, $orig_pos, 0, -1 ); 345 } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. 343 } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. 346 344 $diff_pos = $final_pos - $orig_pos; 347 345 while ( $diff_pos < 0 ) 348 346 array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); 349 } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. 347 } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. 350 348 $diff_pos = $orig_pos - $final_pos; 351 349 while ( $diff_pos < 0 ) … … 353 351 } 354 352 } 355 356 353 357 354 // Pad the ends with blank rows if the columns aren't the same length … … 428 425 $difference = array_sum( array_map( array(&$this, 'difference'), $chars1, $chars2 ) ); 429 426 430 // $string1 has zero length? Odd. 427 // $string1 has zero length? Odd. Give huge penalty by not dividing. 431 428 if ( !$string1 ) 432 429 return $difference; … … 474 471 475 472 } 476 477 ?>
Note: See TracChangeset
for help on using the changeset viewer.