Checking in experimental diff system that's been rewritten
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 17 Dec 2005 05:07:35 +0000 (05:07 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 17 Dec 2005 05:07:35 +0000 (05:07 +0000)
includes/svnlib.php

index ebdceaa66ec5172b94cf530834c3f4ebb85f6f39..282ab575df8ee5789f9c302adf8e9b4f4e71a04d 100644 (file)
@@ -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));