From 5031b7f3c017c054bd8aa3a5462d05d1321e59d7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 17 Dec 2005 05:07:35 +0000 Subject: [PATCH] Checking in experimental diff system that's been rewritten --- includes/svnlib.php | 69 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/includes/svnlib.php b/includes/svnlib.php index ebdceaa..282ab57 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -851,6 +851,8 @@ class SVNDiff */ function process() { + global $viewsvn; + $chunk = 0; $indexcounter = null; @@ -897,7 +899,7 @@ class SVNDiff $delstack = array(); } else if ($act == '+') - { + { // potential line delta if (count($delstack) > 0) { @@ -905,8 +907,28 @@ class SVNDiff if ($delta = @$this->fetch_diff_extent($lastline['line'], $content)) { + //$delta['end'] = $delta['start'] + -$delta['end']; + //print_r($delta); + //$change = ''; + if (strlen($lastline['line']) > ($delta['start'] - $delta['end'])) + { + $end = strlen($lastline['line']) + $delta['end']; + $viewsvn->debug("RM delta- = " . $end); + $change = '{@-' . '-}' . substr($lastline['line'], $delta['start'], $end - $delta['start']) . '{/@-' . '-}'; + $this->diff["$index"]["$chunk"]["$lastline[INDEX]"]['line'] = substr($lastline['line'], 0, $delta['start']) . $change . substr($lastline['line'], $end); + } + + //$change = ''; + if (strlen($content) > $delta['start'] - $delta['end']) + { + $end = strlen($content) + $delta['end']; + $viewsvn->debug("MK delta+ = " . $end); + $change = '{@+' . '+}' . substr($content, $delta['start'], $end - $delta['start']) . '{/@+' . '+}'; + $content = substr($content, 0, $delta['start']) . $change . substr($content, $end); + } + // create two sets of ends for the two contents - $delta['endo'] = strlen($lastline['line']) - $delta['end']; + /*$delta['endo'] = strlen($lastline['line']) - $delta['end']; $delta['endn'] = strlen($content) - $delta['end']; $diffo = $delta['endo'] - $delta['start']; @@ -922,7 +944,7 @@ class SVNDiff { $added = substr($content, $delta['start'], $diffn); $content = substr_replace($content, '{@+' . '+}' . $added . '{/@+' . '+}', $delta['start'], $diffn); - } + }*/ } } @@ -983,6 +1005,47 @@ class SVNDiff * @return array Difference of positions */ function fetch_diff_extent($old, $new) + { + global $viewsvn; + + $start = 0; + $min = min(strlen($old), strlen($new)); + + $viewsvn->debug("min1 = $min"); + + while ($start < $min AND $old{"$start"} == $new{"$start"}) + { + $start++; + } + + $end = -1; + $min = $min - $start; + + $viewsvn->debug("min2 = $min"); + + $viewsvn->debug("checking: " . $old{ strlen($old) + $end } . ' == ' . $new{ strlen($new) + $end }); + + while (-$end <= $min AND $old{ strlen($old) + $end } == $new{ strlen($new) + $end }) + { + $end--; + } + + return array('start' => $start, 'end' => $end + 1, 'min' => $min); + } + + /** + * Returns the amount of change that occured + * between two lines + * + * @access private + * @deprecated Use the fetch_diff_extent() function; this one calculates incorrect end deltas + * + * @param string Old line + * @param string New line + * + * @return array Difference of positions + */ + function fetch_diff_extent2($old, $new) { $start = 0; $min = min(strlen($old), strlen($new)); -- 2.43.5