From a0915d4f734c436dfb7813209cbe5c2268c8a540 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 28 Aug 2005 06:46:12 +0000 Subject: [PATCH] Got the advanced diff finally working now? --- dev/difftest.php | 2 +- includes/svnlib.php | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/dev/difftest.php b/dev/difftest.php index b16b504..d4b064e 100644 --- a/dev/difftest.php +++ b/dev/difftest.php @@ -17,7 +17,7 @@ require_once('./global.php'); // diff /bugtrack/trunk/index@351:359 -$diff = new SVNDiff('bugtrack', '/trunk/index.php', 351, 359); +$diff = new SVNDiff('bugtrack', '/trunk/admin/usergroup.php', 380, 386); echo << diff --git a/includes/svnlib.php b/includes/svnlib.php index 8ba1b9a..940d19d 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -564,18 +564,23 @@ class SVNDiff { if ($delta = @$this->fetch_diff_extent($lastcontent, $content)) { - $diff = $delta['end'] - $delta['start']; + // create two sets of ends for the two contents + $delta['endo'] = strlen($lastcontent) - $delta['end']; + $delta['endn'] = strlen($content) - $delta['end']; - if (strlen($lastcontent) > $delta['end'] - $diff) + $diffo = $delta['endo'] - $delta['start']; + $diffn = $delta['endn'] - $delta['start']; + + if (strlen($lastcontent) > $delta['endo'] - $diffo) { - $removed = substr($lastcontent, $delta['start'], $diff); - $this->diff["$chunk"][ count($this->diff["$chunk"]) - 2 ]['line'] = substr_replace($lastcontent, '{@--}' . $removed . '{/@--}', $delta['start'], $diff); + $removed = substr($lastcontent, $delta['start'], $diffo); + $this->diff["$chunk"][ count($this->diff["$chunk"]) - 2 ]['line'] = substr_replace($lastcontent, '{@--}' . $removed . '{/@--}', $delta['start'], $diffo); } - if (strlen($content) > $delta['end'] - $diff) + if (strlen($content) > $delta['endn'] - $diffn) { - $added = substr($content, $delta['start'], $diff); - $content = substr_replace($content, '{@++}' . $added . '{/@++}', $delta['start'], $diff); + $added = substr($content, $delta['start'], $diffn); + $content = substr_replace($content, '{@++}' . $added . '{/@++}', $delta['start'], $diffn); } } } @@ -642,15 +647,19 @@ class SVNDiff $max = max(strlen($old), strlen($new)); - for ($end = $max; $end > 0; $end--) + for ($end = 0; $end < $min; $end++) { - if ($old{"$end"} != $new{"$end"}) + $oldpos = strlen($old) - $end; + $newpos = strlen($new) - $end; + + if ($old{"$oldpos"} != $new{"$newpos"}) { + echo $old{"$oldpos"} . ':' . $new{"$newpos"}; break; } } - $end++; + $end--; if ($start == 0 AND $end == $max) { -- 2.22.5