Exemplo n.º 1
0
function diff_result($all, $ent, $newtname, $oldtname, $obj)
{
    $ofile = fopen($oldtname, 'r');
    $nfile = fopen($newtname, 'r');
    // Get the first real line
    $line = nextLine($obj);
    $index = 0;
    $listing = array();
    $curoline = 1;
    $curnline = 1;
    while (!endOfFile($obj)) {
        // Get the first line of this range
        $oline = 0;
        sscanf($line, '@@ -%d', $oline);
        $line = substr($line, strpos($line, '+'));
        $nline = 0;
        sscanf($line, '+%d', $nline);
        while ($curoline < $oline || $curnline < $nline) {
            if ($all) {
                $listing[$index]['rev1diffclass'] = 'diff';
                $listing[$index]['rev2diffclass'] = 'diff';
            }
            if ($curoline < $oline) {
                $nl = fgets($ofile);
                if ($all) {
                    $line = rtrim($nl);
                    if ($ent) {
                        $line = replaceEntities($line);
                    } else {
                        $line = toOutputEncoding($line);
                    }
                    if (strip_tags($line) == '') {
                        $line = '&nbsp;';
                    }
                    $listing[$index]['rev1line'] = wrapInCodeTagIfNecessary($line);
                }
                $curoline++;
            } else {
                if ($all) {
                    $listing[$index]['rev1line'] = '&nbsp;';
                }
            }
            if ($curnline < $nline) {
                $nl = fgets($nfile);
                if ($all) {
                    $line = rtrim($nl);
                    if ($ent) {
                        $line = replaceEntities($line);
                    } else {
                        $line = toOutputEncoding($line);
                    }
                    if (strip_tags($line) == '') {
                        $line = '&nbsp;';
                    }
                    $listing[$index]['rev2line'] = wrapInCodeTagIfNecessary($line);
                }
                $curnline++;
            } else {
                if ($all) {
                    $listing[$index]['rev2line'] = '&nbsp;';
                }
            }
            if ($all) {
                $listing[$index]['rev1lineno'] = 0;
                $listing[$index]['rev2lineno'] = 0;
                $index++;
            }
        }
        if (!$all) {
            // Output the line numbers
            $listing[$index]['rev1lineno'] = $oline;
            $listing[$index]['rev2lineno'] = $nline;
            $index++;
        }
        $fin = false;
        while (!endOfFile($obj) && !$fin) {
            $line = nextLine($obj);
            if ($line === false || $line === '' || strncmp($line, '@@', 2) == 0) {
                $fin = true;
            } else {
                $listing[$index]['rev1lineno'] = 0;
                $listing[$index]['rev2lineno'] = 0;
                $mod = $line[0];
                $line = rtrim(substr($line, 1));
                if ($ent) {
                    $line = replaceEntities($line);
                } else {
                    $line = toOutputEncoding($line);
                }
                if (strip_tags($line) == '') {
                    $line = '&nbsp;';
                }
                $text = wrapInCodeTagIfNecessary($line);
                $listing[$index]['rev1line'] = $text;
                switch ($mod) {
                    case '-':
                        $listing[$index]['rev1diffclass'] = 'diffdeleted';
                        $listing[$index]['rev2diffclass'] = 'diff';
                        $listing[$index]['rev1line'] = $text;
                        $listing[$index]['rev2line'] = '&nbsp;';
                        fgets($ofile);
                        $curoline++;
                        break;
                    case '+':
                        // Try to mark "changed" line sensibly
                        if (!empty($listing[$index - 1]) && empty($listing[$index - 1]['rev1lineno']) && @$listing[$index - 1]['rev1diffclass'] == 'diffdeleted' && @$listing[$index - 1]['rev2diffclass'] == 'diff') {
                            $i = $index - 1;
                            while (!empty($listing[$i - 1]) && empty($listing[$i - 1]['rev1lineno']) && $listing[$i - 1]['rev1diffclass'] == 'diffdeleted' && $listing[$i - 1]['rev2diffclass'] == 'diff') {
                                $i--;
                            }
                            $listing[$i]['rev1diffclass'] = 'diffchanged';
                            $listing[$i]['rev2diffclass'] = 'diffchanged';
                            $listing[$i]['rev2line'] = $text;
                            fgets($nfile);
                            $curnline++;
                            // Don't increment the current index count
                            $index--;
                        } else {
                            $listing[$index]['rev1diffclass'] = 'diff';
                            $listing[$index]['rev2diffclass'] = 'diffadded';
                            $listing[$index]['rev1line'] = '&nbsp;';
                            $listing[$index]['rev2line'] = $text;
                            fgets($nfile);
                            $curnline++;
                        }
                        break;
                    default:
                        $listing[$index]['rev1diffclass'] = 'diff';
                        $listing[$index]['rev2diffclass'] = 'diff';
                        $nl = fgets($ofile);
                        $line = rtrim($nl);
                        if ($ent) {
                            $line = replaceEntities($line);
                        } else {
                            $line = toOutputEncoding($line);
                        }
                        if (strip_tags($line) == '') {
                            $line = '&nbsp;';
                        }
                        $listing[$index]['rev1line'] = wrapInCodeTagIfNecessary($line);
                        $curoline++;
                        $nl = fgets($nfile);
                        $line = rtrim($nl);
                        if ($ent) {
                            $line = replaceEntities($line);
                        } else {
                            $line = toOutputEncoding($line);
                        }
                        if (strip_tags($line) == '') {
                            $line = '&nbsp;';
                        }
                        $listing[$index]['rev2line'] = wrapInCodeTagIfNecessary($line);
                        $curnline++;
                        break;
                }
            }
            if (!$fin) {
                $index++;
            }
        }
    }
    // Output the rest of the files
    if ($all) {
        while (!feof($ofile) || !feof($nfile)) {
            $listing[$index]['rev1diffclass'] = 'diff';
            $listing[$index]['rev2diffclass'] = 'diff';
            $line = rtrim(fgets($ofile));
            if ($ent) {
                $line = replaceEntities($line);
            } else {
                $line = toOutputEncoding($line);
            }
            if (strip_tags($line) == '') {
                $line = '&nbsp;';
            }
            if (!feof($ofile)) {
                $listing[$index]['rev1line'] = wrapInCodeTagIfNecessary($line);
            } else {
                $listing[$index]['rev1line'] = '&nbsp;';
            }
            $line = rtrim(fgets($nfile));
            if ($ent) {
                $line = replaceEntities(rtrim(fgets($nfile)));
            } else {
                $line = toOutputEncoding($line);
            }
            if (strip_tags($line) == '') {
                $line = '&nbsp;';
            }
            if (!feof($nfile)) {
                $listing[$index]['rev2line'] = wrapInCodeTagIfNecessary($line);
            } else {
                $listing[$index]['rev2line'] = '&nbsp;';
            }
            $listing[$index]['rev1lineno'] = 0;
            $listing[$index]['rev2lineno'] = 0;
            $index++;
        }
    }
    fclose($ofile);
    fclose($nfile);
    return $listing;
}
Exemplo n.º 2
0
 function listFileContents($path, $rev = 0, $peg = '')
 {
     global $config, $extEnscript;
     $ext = strrchr($path, '.');
     if ($config->useGeshi && ($geshiLang = $this->highlightLanguageUsingGeshi($ext))) {
         $tempname = tempnam($config->getTempDir(), 'wsvn');
         print toOutputEncoding($this->applyGeshi($path, $tempname, $geshiLang, $rev, $peg, true));
         @unlink($tempname);
     } else {
         $pre = false;
         $path = encodepath($this->getSvnPath($path));
         $pegrev = $peg ? '@' . $peg : '';
         $cmd = $config->getSvnCommand() . ' cat -r ' . $rev . ' ' . $this->repConfig->svnParams() . quote($path . $pegrev);
         if ($config->useEnscript) {
             $l = @$extEnscript[$ext];
             $cmd .= ' | ' . $config->enscript . ' --language=html ' . ($l ? '--color --pretty-print=' . $l : '') . ' -o - | ' . $config->sed . ' -n ' . $config->quote . '/^<PRE.$/,/^<\\/PRE.$/p' . $config->quote;
         } else {
             $pre = true;
         }
         if ($result = popenCommand($cmd, 'r')) {
             if ($pre) {
                 echo '<pre>';
             }
             while (!feof($result)) {
                 $line = fgets($result, 1024);
                 if ($pre) {
                     $line = replaceEntities($line, $this->repConfig);
                 } else {
                     $line = toOutputEncoding($line);
                 }
                 print hardspace($line);
             }
             if ($pre) {
                 echo '</pre>';
             }
             pclose($result);
         }
     }
 }
Exemplo n.º 3
0
     } else {
         $newline = $newlineR < $newlineN ? $newlineR : $newlineN;
         $line = substr($bufferedLine, 0, $newline);
         $bufferedLine = substr($bufferedLine, $newline + 1);
     }
 }
 clearVars();
 $getLine = true;
 if ($debug) {
     print 'Line = "' . $line . '"<br />';
 }
 if ($indiff) {
     // If we're in a diff proper, just set up the line
     if ($indiffproper) {
         if (strlen($line) > 0 && ($line[0] == ' ' || $line[0] == '+' || $line[0] == '-')) {
             $subline = replaceEntities(substr($line, 1));
             $subline = $subline ? expandTabs($subline) : '&nbsp;';
             $listing[$index]['line'] = $subline;
             switch ($line[0]) {
                 case ' ':
                     $listing[$index]['diffclass'] = 'diff';
                     if ($debug) {
                         print 'Including as diff: ' . $subline . '<br />';
                     }
                     break;
                 case '+':
                     $listing[$index]['diffclass'] = 'diffadded';
                     if ($debug) {
                         print 'Including as added: ' . $subline . '<br />';
                     }
                     break;
Exemplo n.º 4
0
                 $listing[$index]['lineno'] = $index + 1;
                 if ($last_rev != $revision) {
                     $url = $config->getURL($rep, $parent, 'revision');
                     $listing[$index]['revision'] = '<a id="l' . $index . '-rev" class="blame-revision" href="' . $url . 'rev=' . $revision . '&amp;peg=' . $rev . '">' . $revision . '</a>';
                     $seen_rev[$revision] = 1;
                     $row_class = $row_class == 'light' ? 'dark' : 'light';
                     $listing[$index]['author'] = $author;
                 } else {
                     $listing[$index]['revision'] = '';
                     $listing[$index]['author'] = '';
                 }
                 $listing[$index]['row_class'] = $row_class;
                 $last_rev = $revision;
                 $line = rtrim(fgets($file));
                 if (!$highlighted) {
                     $line = replaceEntities($line);
                 }
                 $listing[$index]['line'] = $empty ? '&nbsp;' : wrapInCodeTagIfNecessary($line);
                 $index++;
             }
         }
         fclose($blame);
     }
     fclose($file);
     @unlink($tbname);
 }
 @unlink($tfname);
 // Build the necessary JavaScript as an array of lines, then join them with \n
 $javascript = array();
 $javascript[] = '<script type="text/javascript" src="' . $locwebsvnhttp . '/javascript/blame-popup.js"></script>';
 $javascript[] = '<script type="text/javascript">';