jablonka.czprosek.czf

websvn

Subversion Repositories:
[/] [diff.php] - Diff between revs 1 and 3

Show entire file Ignore whitespace

Rev 1 Rev 3
Line 26... Line 26...
require_once("include/setup.php"); require_once("include/setup.php");
require_once("include/svnlook.php"); require_once("include/svnlook.php");
require_once("include/utils.php"); require_once("include/utils.php");
require_once("include/template.php"); require_once("include/template.php");
   
$context = 5; require_once("include/diff_inc.php");
   
$vars["action"] = $lang["DIFF"]; $vars["action"] = $lang["DIFF"];
$all = (@$_REQUEST["all"] == 1)?1:0; $all = (@$_REQUEST["all"] == 1);
  $ignoreWhitespace = (@$_REQUEST["ignorews"] == 1);
   
// Make sure that we have a repository // Make sure that we have a repository
if (!isset($rep)) { if (!isset($rep)) {
echo $lang["NOREP"]; echo $lang["NOREP"];
exit; exit;
Line 41... Line 42...
   
$svnrep = new SVNRepository($rep); $svnrep = new SVNRepository($rep);
   
// If there's no revision info, go to the lastest revision for this path // If there's no revision info, go to the lastest revision for this path
$history = $svnrep->getLog($path, "", "", true); $history = $svnrep->getLog($path, "", "", true);
  if (is_string($history)) {
  echo $history;
  exit;
  }
$youngest = $history->entries[0]->rev; $youngest = $history->entries[0]->rev;
   
if (empty($rev)) { if (empty($rev)) {
$rev = $youngest; $rev = $youngest;
} }
   
$history = $svnrep->getLog($path, $rev); $history = $svnrep->getLog($path, $rev);
  if (is_string($history)) {
  echo $history;
  exit;
  }
   
if ($path{0} != "/") { if ($path{0} != "/") {
$ppath = "/".$path; $ppath = "/".$path;
} else { } else {
$ppath = $path; $ppath = $path;
Line 95... Line 104...
   
if ($prevrev) { if ($prevrev) {
$url = $config->getURL($rep, $path, "diff"); $url = $config->getURL($rep, $path, "diff");
   
if (!$all) { if (!$all) {
$vars["showalllink"] = "<a href=\"${url}rev=$rev&amp;all=1\">${lang["SHOWENTIREFILE"]}</a>"; $vars["showalllink"] = '<a href="'.$url.'rev='.$rev.'&amp;all=1&amp;ignorews='.($ignoreWhitespace ? '1' : '0').'">'.$lang['SHOWENTIREFILE'].'</a>';
$vars["showcompactlink"] = ""; $vars["showcompactlink"] = '';
} else { } else {
$vars["showcompactlink"] = "<a href=\"${url}rev=$rev&amp;all=0\">${lang["SHOWCOMPACT"]}</a>"; $vars["showcompactlink"] = '<a href="'.$url.'rev='.$rev.'&amp;all=0&amp;ignorews='.($ignoreWhitespace ? '1' : '0').'">'.$lang['SHOWCOMPACT'].'</a>';
$vars["showalllink"] = ""; $vars["showalllink"] = '';
  }
  if (!$ignoreWhitespace) {
  $vars['ignorewhitespacelink'] = '<a href="'.$url.'rev='.$rev.'&amp;all='.($all ? '1' : '0').'&amp;ignorews=1">'.$lang['IGNOREWHITESPACE'].'</a>';
  $vars['regardwhitespacelink'] = '';
  } else {
  $vars['regardwhitespacelink'] = '<a href="'.$url.'rev='.$rev.'&amp;all='.($all ? '1' : '0').'&amp;ignorews=0">'.$lang['REGARDWHITESPACE'].'</a>';
  $vars['ignorewhitespacelink'] = '';
} }
   
// Get the contents of the two files // Get the contents of the two files
$newtname = tempnam("temp", ""); $newtname = tempnam("temp", "");
$svnrep->getFileContents($history->entries[0]->path, $newtname, $history->entries[0]->rev, "", true); $highlightedNew = $svnrep->getFileContents($history->entries[0]->path, $newtname, $history->entries[0]->rev, "", true);
   
$oldtname = tempnam("temp", ""); $oldtname = tempnam("temp", "");
$svnrep->getFileContents($history->entries[1]->path, $oldtname, $history->entries[1]->rev, "", true); $highlightedOld = $svnrep->getFileContents($history->entries[1]->path, $oldtname, $history->entries[1]->rev, "", true);
   
$ent = true; $ent = (!$highlightedNew && !$highlightedOld);
$extension = strrchr(basename($path), "."); $listing = do_diff($all, $ignoreWhitespace, $rep, $ent, $newtname, $oldtname);
if (($extension && isset($extEnscript[$extension]) && ('php' == $extEnscript[$extension])) || ($config->useEnscript || $config->useGeshi)) {  
$ent = false;  
}  
   
if ($all) {  
// Setting the context to 0 makes diff generate the wrong line numbers!  
$context = 1;  
}  
   
// Open a pipe to the diff command with $context lines of context  
   
$cmd = quoteCommand($config->diff." -w -U $context \"$oldtname\" \"$newtname\"");  
   
if ($all) {  
$ofile = fopen($oldtname, "r");  
$nfile = fopen($newtname, "r");  
}  
   
$descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));  
   
$resource = proc_open($cmd, $descriptorspec, $pipes);  
$error = "";  
   
if (is_resource($resource)) {  
// We don't need to write  
fclose($pipes[0]);  
   
$diff = $pipes[1];  
   
// Ignore the 3 header lines  
$line = fgets($diff);  
$line = fgets($diff);  
   
// Get the first real line  
$line = fgets($diff);  
   
$index = 0;  
$listing = array();  
   
$curoline = 1;  
$curnline = 1;  
   
while (!feof($diff)) {  
// Get the first line of this range  
sscanf($line, "@@ -%d", $oline);  
   
$line = substr($line, strpos($line, "+"));  
sscanf($line, "+%d", $nline);  
   
if ($all) {  
while ($curoline < $oline || $curnline < $nline) {  
$listing[$index]["rev1diffclass"] = "diff";  
$listing[$index]["rev2diffclass"] = "diff";  
   
if ($curoline < $oline) {  
$nl = fgets($ofile);  
   
$line = rtrim($nl);  
if ($ent) $line = replaceEntities($line, $rep);  
   
$listing[$index]["rev1line"] = hardspace($line);  
   
$curoline++;  
} else {  
$listing[$index]["rev1line"] = "&nbsp;";  
}  
   
if ($curnline < $nline) {  
$nl = fgets($nfile);  
   
$line = rtrim($nl);  
if ($ent) $line = replaceEntities($line, $rep);  
   
$listing[$index]["rev2line"] = hardspace($line);  
$curnline++;  
} else {  
$listing[$index]["rev2line"] = "&nbsp;";  
}  
   
$listing[$index]["rev1lineno"] = 0;  
$listing[$index]["rev2lineno"] = 0;  
   
$index++;  
}  
   
} else {  
// Output the line numbers  
$listing[$index]["rev1lineno"] = $oline;  
$listing[$index]["rev2lineno"] = $nline;  
$index++;  
}  
   
$fin = false;  
while (!feof($diff) && !$fin) {  
$line = fgets($diff);  
if ($line === false || 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, $rep);  
   
if (strip_tags($line) == '') $line = '&nbsp;';  
$listing[$index]["rev1line"] = hardspace($line);  
   
$text = hardspace($line);  
   
switch ($mod) {  
case "-":  
$listing[$index]["rev1diffclass"] = "diffdeleted";  
$listing[$index]["rev2diffclass"] = "diff";  
   
$listing[$index]["rev1line"] = $text;  
$listing[$index]["rev2line"] = "&nbsp;";  
   
if ($all) {  
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;  
   
if ($all) {  
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;  
   
if ($all) {  
fgets($nfile);  
$curnline++;  
}  
}  
break;  
   
default:  
$listing[$index]["rev1diffclass"] = "diff";  
$listing[$index]["rev2diffclass"] = "diff";  
   
$listing[$index]["rev1line"] = $text;  
$listing[$index]["rev2line"] = $text;  
   
if ($all) {  
fgets($ofile);  
fgets($nfile);  
$curoline++;  
$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, $rep);  
   
if (!feof($ofile)) {  
$listing[$index]["rev1line"] = hardspace($line);  
} else {  
$listing[$index]["rev1line"] = "&nbsp;";  
}  
   
$line = rtrim(fgets($nfile));  
if ($ent) $line = replaceEntities(rtrim(fgets($nfile)), $rep);  
   
if (!feof($nfile)) {  
$listing[$index]["rev2line"] = hardspace($line);  
} else {  
$listing[$index]["rev2line"] = "&nbsp;";  
}  
   
$listing[$index]["rev1lineno"] = 0;  
$listing[$index]["rev2lineno"] = 0;  
   
$index++;  
}  
}  
   
fclose($pipes[1]);  
   
while (!feof($pipes[2])) {  
$error .= fgets($pipes[2]);  
}  
   
$error = toOutputEncoding(trim($error));  
   
if (!empty($error)) $error = "<p>".$lang['BADCMD'].": <code>".$cmd."</code></p><p>".nl2br($error)."</p>";  
   
fclose($pipes[2]);  
   
proc_close($resource);  
   
} else {  
$error = "<p>".$lang['BADCMD'].": <code>".$cmd."</code></p>";  
}  
   
if (!empty($error)) {  
echo $error;  
   
if (is_resource($resource)) {  
fclose($pipes[0]);  
fclose($pipes[1]);  
fclose($pipes[2]);  
   
proc_close($resource);  
}  
exit;  
}  
   
if ($all) {  
fclose($ofile);  
fclose($nfile);  
}  
   
// Remove our temporary files // Remove our temporary files
@unlink($oldtname); @unlink($oldtname);
@unlink($newtname); @unlink($newtname);
   

Powered by WebSVN 2.2.1