Exemplo n.º 1
0
 function __diff3($edits1, $edits2)
 {
     $blocks = array();
     $bb = new _Diff3_BlockBuilder();
     $e1 = current($edits1);
     $e2 = current($edits2);
     while ($e1 || $e2) {
         //          echo "====\n";
         //          print_r($e1);
         //          print_r($e2);
         //          echo "====\n";
         if ($e1 && $e2 && $e1->type == 'copy' && $e2->type == 'copy') {
             // We have copy blocks from both diffs.  This is the (only)
             // time we want to emit a diff3 copy block.
             // Flush current diff3 diff block, if any
             if ($block = $bb->finish()) {
                 $blocks[] = $block;
             }
             $ncopy = min($e1->norig(), $e2->norig());
             assert($ncopy > 0);
             $blocks[] = new _Diff3_CopyBlock(array_slice($e1->orig, 0, $ncopy));
             if ($e1->norig() > $ncopy) {
                 array_splice($e1->orig, 0, $ncopy);
                 array_splice($e1->final, 0, $ncopy);
             } else {
                 $e1 = next($edits1);
             }
             if ($e2->norig() > $ncopy) {
                 array_splice($e2->orig, 0, $ncopy);
                 array_splice($e2->final, 0, $ncopy);
             } else {
                 $e2 = next($edits2);
             }
         } else {
             if ($e1 && $e2) {
                 if ($e1->orig && $e2->orig) {
                     $norig = min($e1->norig(), $e2->norig());
                     $orig = array_splice($e1->orig, 0, $norig);
                     array_splice($e2->orig, 0, $norig);
                     $bb->input($orig);
                 }
                 if ($e1->type == 'copy') {
                     $bb->out1(array_splice($e1->final, 0, $norig));
                 }
                 if ($e2->type == 'copy') {
                     $bb->out2(array_splice($e2->final, 0, $norig));
                 }
             }
             if ($e1 && !$e1->orig) {
                 $bb->out1($e1->final);
                 $e1 = next($edits1);
             }
             if ($e2 && !$e2->orig) {
                 $bb->out2($e2->final);
                 $e2 = next($edits2);
             }
         }
     }
     if ($block = $bb->finish()) {
         $blocks[] = $block;
     }
     return $blocks;
 }
Exemplo n.º 2
0
 /**
  * @access private
  */
 function _diff3($edits1, $edits2)
 {
     $edits = array();
     $bb = new _Diff3_BlockBuilder();
     $e1 = current($edits1);
     $e2 = current($edits2);
     while ($e1 || $e2) {
         if ($e1 && $e2 && is_a($e1, '_DiffOp_copy') && is_a($e2, '_DiffOp_copy')) {
             /* We have copy blocks from both diffs. This is the (only)
              * time we want to emit a diff3 copy block.  Flush current
              * diff3 diff block, if any. */
             if ($edit = $bb->finish()) {
                 $edits[] = $edit;
             }
             $ncopy = min($e1->norig(), $e2->norig());
             assert($ncopy > 0);
             $edits[] = new _Diff3_Op_copy(array_slice($e1->orig, 0, $ncopy));
             if ($e1->norig() > $ncopy) {
                 array_splice($e1->orig, 0, $ncopy);
                 array_splice($e1->closing, 0, $ncopy);
             } else {
                 $e1 = next($edits1);
             }
             if ($e2->norig() > $ncopy) {
                 array_splice($e2->orig, 0, $ncopy);
                 array_splice($e2->closing, 0, $ncopy);
             } else {
                 $e2 = next($edits2);
             }
         } else {
             if ($e1 && $e2) {
                 if ($e1->orig && $e2->orig) {
                     $norig = min($e1->norig(), $e2->norig());
                     $orig = array_splice($e1->orig, 0, $norig);
                     array_splice($e2->orig, 0, $norig);
                     $bb->input($orig);
                 }
                 if (is_a($e1, '_DiffOp_copy')) {
                     $bb->out1(array_splice($e1->closing, 0, $norig));
                 }
                 if (is_a($e2, '_DiffOp_copy')) {
                     $bb->out2(array_splice($e2->closing, 0, $norig));
                 }
             }
             if ($e1 && !$e1->orig) {
                 $bb->out1($e1->closing);
                 $e1 = next($edits1);
             }
             if ($e2 && !$e2->orig) {
                 $bb->out2($e2->closing);
                 $e2 = next($edits2);
             }
         }
     }
     if ($edit = $bb->finish()) {
         $edits[] = $edit;
     }
     return $edits;
 }