From 0f3ea44ab52f06582c2eac0fce491c41ad0a6f75 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 28 Aug 2005 07:23:37 +0000 Subject: [PATCH] Added multi file support in diffs --- dev/difftest.php | 71 +++++++++++++++++++++++++-------------------- includes/svnlib.php | 37 +++++++++++++++-------- 2 files changed, 65 insertions(+), 43 deletions(-) diff --git a/dev/difftest.php b/dev/difftest.php index d4b064e..997438c 100644 --- a/dev/difftest.php +++ b/dev/difftest.php @@ -17,7 +17,9 @@ require_once('./global.php'); // diff /bugtrack/trunk/index@351:359 -$diff = new SVNDiff('bugtrack', '/trunk/admin/usergroup.php', 380, 386); +$diff = new SVNDiff('bugtrack', '/trunk/', 383, 385); + +//print_r($diff); echo << @@ -42,46 +44,53 @@ echo << HTML; -echo ''; - -foreach ($diff->fetch() AS $hunk) +foreach ($diff->fetch() AS $filename => $file) { - foreach ($hunk AS $key => $line) + echo '

' . $filename . '

'; + + foreach ($file AS $hunk) { - if ($key == 'hunk' AND isset($line['old'])) - { - echo ' - - - '; - continue; - } + echo '
 
'; - if ($line['act'] == '+') + foreach ($hunk AS $key => $line) { - $color = '#DDFFDD'; - } - else if ($line['act'] == '-') - { - $color = '#FFDDDD'; - } - else - { - $color = 'white'; + if ($key == 'hunk' AND isset($line['old'])) + { + echo ' + + + '; + continue; + } + + if ($line['act'] == '+') + { + $color = '#DDFFDD'; + } + else if ($line['act'] == '-') + { + $color = '#FFDDDD'; + } + else + { + $color = 'white'; + } + + echo ' + + + + + '; } echo ' - - - - - '; +
 
' . $line['oldlineno'] . '' . $line['newlineno'] . '' . $viewsvn->svn->format($line['line']) . '
' . $line['oldlineno'] . '' . $line['newlineno'] . '' . $viewsvn->svn->format($line['line']) . '
'; } + + echo '
'; } -echo ' -'; - /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/includes/svnlib.php b/includes/svnlib.php index 7c3a5aa..451cbcf 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -519,7 +519,8 @@ class SVNDiff function process() { $chunk = 0; - $capture = false; + $indexcounter = null; + $lastact = ''; $lastcontent = ''; @@ -527,19 +528,23 @@ class SVNDiff { if (preg_match('#^@@ \-([0-9]*),([0-9]*) \+([0-9]*),([0-9]*) @@$#', $line, $bits)) { - $capture = true; $lastact = ''; $lastcontent = ''; - $this->diff[ ++$chunk ]['hunk'] = array('old' => array('line' => $bits[1], 'count' => $bits[2]), 'new' => array('line' => $bits[3], 'count' => $bits[4])); - $lines['old'] = $this->diff["$chunk"]['hunk']['old']['line'] - 1; - $lines['new'] = $this->diff["$chunk"]['hunk']['new']['line'] - 1; + $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; continue; } - // ensures we don't capture before the first hunk - if (!$capture) + if ($indexcounter <= 5 AND $indexcounter !== null) + { + $indexcounter++; + continue; + } + else if ($indexcounter == 5) { + $indexcounter = null; continue; } @@ -550,7 +555,7 @@ class SVNDiff if ($act == ' ') { - $this->diff["$chunk"][] = array( + $this->diff["$index"]["$chunk"][] = array( 'line' => $content, 'act' => '', 'oldlineno' => ++$lines['old'], @@ -574,7 +579,7 @@ class SVNDiff if (strlen($lastcontent) > $delta['endo'] - $diffo) { $removed = substr($lastcontent, $delta['start'], $diffo); - $this->diff["$chunk"][ count($this->diff["$chunk"]) - 2 ]['line'] = substr_replace($lastcontent, '{@--}' . $removed . '{/@--}', $delta['start'], $diffo); + $this->diff["$index"]["$chunk"][ count($this->diff["$index"]["$chunk"]) - 2 ]['line'] = substr_replace($lastcontent, '{@--}' . $removed . '{/@--}', $delta['start'], $diffo); } if (strlen($content) > $delta['endn'] - $diffn) @@ -585,7 +590,7 @@ class SVNDiff } } - $this->diff["$chunk"][] = array( + $this->diff["$index"]["$chunk"][] = array( 'line' => $content, 'act' => '+', 'oldlineno' => '', @@ -596,7 +601,7 @@ class SVNDiff { $lastcontent = $content; - $this->diff["$chunk"][] = array( + $this->diff["$index"]["$chunk"][] = array( 'line' => $content, 'act' => '-', 'oldlineno' => ++$lines['old'], @@ -609,9 +614,17 @@ class SVNDiff // whitespace lines else { + if (preg_match('#^Index: (.*?)$#', $line, $matches)) + { + $index = $matches[1]; + $indexcounter = 1; + $chunk = 0; + continue; + } + $lastact = ''; - $this->diff["$chunk"][] = array( + $this->diff["$index"]["$chunk"][] = array( 'line' => '', 'act' => '', 'oldlineno' => ++$lines['old'], -- 2.22.5