From fe254e02e60cda77437ae936319521ea3b06f056 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 11 Sep 2005 16:16:34 +0000 Subject: [PATCH] We can now handle inline diffs that span multiple lines because we match lines --- includes/svnlib.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/includes/svnlib.php b/includes/svnlib.php index 3376ae2..a86557d 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -778,16 +778,13 @@ class SVNDiff $chunk = 0; $indexcounter = null; - $lastact = ''; - $lastcontent = ''; + $delstack = array(); foreach ($this->rawoutput AS $line) { if (preg_match('#^@@ \-([0-9]*),([0-9]*) \+([0-9]*),([0-9]*) @@$#', $line, $bits)) { - $lastact = ''; - $lastcontent = ''; - + $delstack = array(); $this->diff["$index"][ ++$chunk ]['hunk'] = array('old' => array('line' => $bits[1], 'count' => $bits[2]), 'new' => array('line' => $bits[3], 'count' => $bits[4])); $lines['old'] = $this->diff["$index"]["$chunk"]['hunk']['old']['line'] - 1; $lines['new'] = $this->diff["$index"]["$chunk"]['hunk']['new']['line'] - 1; @@ -818,25 +815,29 @@ class SVNDiff 'oldlineno' => ++$lines['old'], 'newlineno' => ++$lines['new'] ); + + $delstack = array(); } else if ($act == '+') { // potential line delta - if ($lastact == '-') + if (count($delstack) > 0) { - if ($delta = @$this->fetch_diff_extent($lastcontent, $content)) + $lastline = array_shift($delstack); + + if ($delta = @$this->fetch_diff_extent($lastline['line'], $content)) { // create two sets of ends for the two contents - $delta['endo'] = strlen($lastcontent) - $delta['end']; + $delta['endo'] = strlen($lastline['line']) - $delta['end']; $delta['endn'] = strlen($content) - $delta['end']; $diffo = $delta['endo'] - $delta['start']; $diffn = $delta['endn'] - $delta['start']; - if (strlen($lastcontent) > $delta['endo'] - $diffo) + if (strlen($lastline['line']) > $delta['endo'] - $diffo) { - $removed = substr($lastcontent, $delta['start'], $diffo); - $this->diff["$index"]["$chunk"][ count($this->diff["$index"]["$chunk"]) - 2 ]['line'] = substr_replace($lastcontent, '{@-' . '-}' . $removed . '{/@-' . '-}', $delta['start'], $diffo); + $removed = substr($lastline['line'], $delta['start'], $diffo); + $this->diff["$index"]["$chunk"]["$lastline[INDEX]"]['line'] = substr_replace($lastline['line'], '{@-' . '-}' . $removed . '{/@-' . '-}', $delta['start'], $diffo); } if (strlen($content) > $delta['endn'] - $diffn) @@ -856,17 +857,18 @@ class SVNDiff } else if ($act == '-') { - $lastcontent = $content; - - $this->diff["$index"]["$chunk"][] = array( + $this->diff["$index"]["$chunk"][] = $thearray = array( 'line' => $content, 'act' => '-', 'oldlineno' => ++$lines['old'], 'newlineno' => '' ); + + $key = count($this->diff["$index"]["$chunk"]) - 2; + $thearray['INDEX'] = $key; + + array_push($delstack, $thearray); } - - $lastact = $act; } // whitespace lines else @@ -879,14 +881,14 @@ class SVNDiff continue; } - $lastact = ''; - $this->diff["$index"]["$chunk"][] = array( 'line' => '', 'act' => '', 'oldlineno' => ++$lines['old'], 'newlineno' => ++$lines['new'] ); + + $delstack = array(); } } } -- 2.43.5