Rev 185 Rev 4988
1 <?php 1 <?php
2 # vim:et:ts=3:sts=3:sw=3:fdm=marker: -  
3   -  
4 // WebSVN - Subversion repository viewing via the web using PHP 2 // WebSVN - Subversion repository viewing via the web using PHP
5 // Copyright © 2004-2006 Tim Armes, Matt Sicker 3 // Copyright (C) 2004-2006 Tim Armes
6 // 4 //
7 // This program is free software; you can redistribute it and/or modify 5 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by 6 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or 7 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version. 8 // (at your option) any later version.
11 // 9 //
12 // This program is distributed in the hope that it will be useful, 10 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details. 13 // GNU General Public License for more details.
16 // 14 //
17 // You should have received a copy of the GNU General Public License 15 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software 16 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // 18 //
21 // -- 19 // --
22 // 20 //
23 // comp.php 21 // comp.php
24 // 22 //
25 // Compare two paths using "svn diff" 23 // Compare two paths using `svn diff`
26 // 24 //
27   25  
28 require_once("include/setup.inc"); 26 require_once 'include/setup.php';
29 require_once("include/svnlook.inc"); 27 require_once 'include/svnlook.php';
30 require_once("include/utils.inc"); 28 require_once 'include/utils.php';
31 require_once("include/template.inc"); 29 require_once 'include/template.php';
32   -  
33 $svnrep = new SVNRepository($rep); -  
34   30  
35 function checkRevision($rev) 31 function checkRevision($rev)
36 { 32 {
37 if (is_numeric($rev) && ((int)$rev > 0)) 33 if (is_numeric($rev) && ((int)$rev > 0))
38 return $rev; -  
39 -  
40 $rev = strtoupper($rev); -  
41 -  
42 switch($rev) -  
43 { 34 {
44 case "HEAD": -  
45 case "PREV": -  
46 case "COMMITTED": -  
47 return $rev; 35 return $rev;
48 } 36 }
-   37 return 'HEAD';
-   38 }
49 39  
50 return "HEAD"; 40 // Make sure that we have a repository
-   41 if (!$rep)
-   42 {
-   43 renderTemplate404('compare','NOREP');
51 } 44 }
52   45  
53 $svnrep = new SVNRepository($rep); 46 $svnrep = new SVNRepository($rep);
54   47  
55 // Retrieve the request information 48 // Retrieve the request information
56 $path1 = @$_REQUEST["compare"][0]; 49 $path1 = @$_REQUEST['compare'][0];
57 $path2 = @$_REQUEST["compare"][1]; 50 $path2 = @$_REQUEST['compare'][1];
58 $rev1 = @$_REQUEST["compare_rev"][0]; 51 $rev1 = (int)@$_REQUEST['compare_rev'][0];
59 $rev2 = @$_REQUEST["compare_rev"][1]; 52 $rev2 = (int)@$_REQUEST['compare_rev'][1];
-   53 $manualorder = (@$_REQUEST['manualorder'] == 1);
-   54 $ignoreWhitespace = $config->getIgnoreWhitespacesInDiff();
-   55  
-   56 if (array_key_exists('ignorews', $_REQUEST))
-   57 {
-   58 $ignoreWhitespace = (bool)$_REQUEST['ignorews'];
-   59 }
60   60  
61 // Some page links put the revision with the path... 61 // Some page links put the revision with the path...
-   62 if ($path1 && strpos($path1, '@'))
-   63 {
62 if (strpos($path1, "@")) list($path1, $rev1) = explode("@", $path1); 64 list($path1, $rev1) = explode('@', $path1);
-   65 }
-   66 else if ($path1 && (strpos($path1, '@') === 0))
-   67 {
-   68 // Something went wrong. The path is missing.
-   69 $rev1 = substr($path1, 1);
-   70 $path1 = '/';
-   71 }
-   72  
-   73 if ($path2 && strpos($path2, '@'))
-   74 {
63 if (strpos($path2, "@")) list($path2, $rev2) = explode("@", $path2); 75 list($path2, $rev2) = explode('@', $path2);
-   76 }
-   77 else if ($path2 && (strpos($path2, '@') === 0))
-   78 {
-   79 $rev2 = substr($path2, 1);
-   80 $path2 = '/';
-   81 }
64   82  
65 $rev1 = checkRevision($rev1); 83 $rev1 = checkRevision($rev1);
66 $rev2 = checkRevision($rev2); 84 $rev2 = checkRevision($rev2);
67   85  
68 // Choose a sensible comparison order unless told not to 86 // Choose a sensible comparison order unless told not to
69 if (!@$_REQUEST["manualorder"] && is_numeric($rev1) && is_numeric($rev2)) -  
70 { 87  
71 if ($rev1 > $rev2) 88 if (!$manualorder && is_numeric($rev1) && is_numeric($rev2) && $rev1 > $rev2)
72 { 89 {
73 $temppath = $path1; 90 $temppath = $path1;
74 $temprev = $rev1; -  
75 -  
76 $path1 = $path2; 91 $path1 = $path2;
77 $rev1 = $rev2; -  
78 -  
79 $path2 = $temppath; 92 $path2 = $temppath;
-   93  
-   94 $temprev = $rev1;
-   95 $rev1 = $rev2;
80 $rev2 = $temprev; 96 $rev2 = $temprev;
81 } 97 }
-   98  
-   99 $vars['rev1url'] = $config->getURL($rep, $path1, 'dir').createRevAndPegString($rev1, $rev1);
-   100 $vars['rev2url'] = $config->getURL($rep, $path2, 'dir').createRevAndPegString($rev2, $rev2);
-   101  
-   102 $url = $config->getURL($rep, '', 'comp');
-   103 $vars['reverselink'] = '<a href="'.$url.'compare%5B%5D='.rawurlencode($path2 ?? '').'@'.$rev2.'&amp;compare%5B%5D='.rawurlencode($path1 ?? '').'@'.$rev1.'&amp;manualorder=1'.($ignoreWhitespace ? '&amp;ignorews=1' : '').'">'.$lang['REVCOMP'].'</a>';
-   104 $toggleIgnoreWhitespace = '';
-   105  
-   106 if ($ignoreWhitespace == $config->getIgnoreWhitespacesInDiff())
-   107 {
-   108 $toggleIgnoreWhitespace = '&amp;ignorews='.($ignoreWhitespace ? '0' : '1');
-   109 }
-   110  
-   111 if (!$ignoreWhitespace)
-   112 {
-   113 $vars['ignorewhitespacelink'] = '<a href="'.$url.'compare%5B%5D='.rawurlencode($path1 ?? '').'@'.$rev1.'&amp;compare%5B%5D='.rawurlencode($path2 ?? '').'@'.$rev2.($manualorder ? '&amp;manualorder=1' : '').$toggleIgnoreWhitespace.'">'.$lang['IGNOREWHITESPACE'].'</a>';
-   114 }
-   115 else
-   116 {
-   117 $vars['regardwhitespacelink'] = '<a href="'.$url.'compare%5B%5D='.rawurlencode($path1 ?? '').'@'.$rev1.'&amp;compare%5B%5D='.rawurlencode($path2 ?? '').'@'.$rev2.($manualorder ? '&amp;manualorder=1' : '').$toggleIgnoreWhitespace.'">'.$lang['REGARDWHITESPACE'].'</a>';
-   118 }
-   119  
-   120 if ($rev1 == 0) $rev1 = 'HEAD';
-   121 if ($rev2 == 0) $rev2 = 'HEAD';
-   122  
-   123 $vars['repname'] = escape($rep->getDisplayName());
-   124 $vars['action'] = $lang['PATHCOMPARISON'];
-   125  
-   126 $hidden = '<input type="hidden" name="manualorder" value="1" />';
-   127  
-   128 if ($config->multiViews)
-   129 {
-   130 $hidden .= '<input type="hidden" name="op" value="comp"/>';
-   131 }
-   132 else
-   133 {
-   134 $hidden .= '<input type="hidden" name="repname" value="'.$repname.'" />';
82 } 135 }
83   136  
84 $url = $config->getURL($rep, "/", "comp"); 137 $vars['compare_form'] = '<form method="get" action="'.$url.'" id="compare">'.$hidden;
-   138 $vars['compare_path1input'] = '<input type="text" size="40" name="compare[0]" value="'.escape($path1).'" />';
-   139 $vars['compare_path2input'] = '<input type="text" size="40" name="compare[1]" value="'.escape($path2).'" />';
-   140 $vars['compare_rev1input'] = '<input type="text" size="5" name="compare_rev[0]" value="'.$rev1.'" />';
-   141 $vars['compare_rev2input'] = '<input type="text" size="5" name="compare_rev[1]" value="'.$rev2.'" />';
85 $vars["revlink"] = "<a href=\"${url}compare%5B%5D=".urlencode($path2)."@$rev2&amp;compare%5B%5D=".urlencode($path1)."@$rev1&manualorder=1\">${lang["REVCOMP"]}</a>"; 142 $vars['compare_submit'] = '<input name="comparesubmit" type="submit" value="'.$lang['COMPAREPATHS'].'" />';
-   143 $vars['compare_endform'] = '</form>';
86   144  
87 if ($rev1 == 0) $rev1 = "HEAD"; 145 $vars['safepath1'] = escape($path1);
88 if ($rev2 == 0) $rev2 = "HEAD"; 146 $vars['safepath2'] = escape($path2);
89   147  
90 $vars["repname"] = $rep->getDisplayName(); 148 $vars['rev1'] = $rev1;
91 $vars["action"] = $lang["PATHCOMPARISON"]; 149 $vars['rev2'] = $rev2;
92 $vars["compare_form"] = "<form action=\"$url\" method=\"post\" name=\"compareform\">"; -  
93 $vars["compare_path1input"] = "<input type=\"text\" size=\"40\" name=\"compare[0]\" value=\"$path1\" />"; -  
94 $vars["compare_rev1input"] = "<input type=\"text\" size=\"5\" name=\"compare_rev[0]\" value=\"$rev1\" />"; -  
95 $vars["compare_path2input"] = "<input type=\"text\" size=\"40\" name=\"compare[1]\" value=\"$path2\" />"; -  
96 $vars["compare_rev2input"] = "<input type=\"text\" size=\"5\" name=\"compare_rev[1]\" value=\"$rev2\" />"; -  
97 $vars["compare_submit"] = "<input name=\"comparesubmit\" type=\"submit\" value=\"${lang["COMPAREPATHS"]}\" />"; -  
98 $vars["compare_endform"] = "<input type=\"hidden\" name=\"op\" value=\"comp\" /><input type=\"hidden\" name=\"manualorder\" value=\"1\" /><input type=\"hidden\" name=\"sc\" value=\"$showchanged\" /></form>"; -  
99   150  
100 # safe paths are a hack for fixing XSS sploit 151 $history1 = $svnrep->getLog($path1, $rev1, 0, false, 1);
101 $vars["path1"] = $path1; 152 if (!$history1)
-   153 {
102 $vars['safepath1'] = htmlentities($path1); 154 renderTemplate404('compare','NOPATH');
-   155 }
103 $vars["path2"] = $path2; 156 else
-   157 {
104 $vars['safepath2'] = htmlentities($path2); 158 $history2 = $svnrep->getLog($path2, $rev2, 0, false, 1);
105   159  
-   160 if (!$history2)
-   161 {
-   162 renderTemplate404('compare','NOPATH');
-   163 }
-   164 }
-   165  
-   166 // Set variables used for the more recent of the two revisions
-   167 $history = ($rev1 >= $rev2 ? $history1 : $history2);
-   168 if ($history && $history->curEntry)
-   169 {
-   170 $logEntry = $history->curEntry;
106 $vars["rev1"] = $rev1; 171 $vars['rev'] = $logEntry->rev;
107 $vars["rev2"] = $rev2; 172 $vars['peg'] = $peg;
-   173 $vars['date'] = $logEntry->date;
-   174 $vars['age'] = datetimeFormatDuration(time() - strtotime($logEntry->date));
-   175 $vars['author'] = $logEntry->author;
-   176 $vars['log'] = xml_entities($logEntry->msg);
-   177 }
-   178 else
-   179 {
-   180 $vars['warning'] = 'Problem with comparison.';
-   181 }
108   182  
109 $noinput = empty($path1) || empty($path2); 183 $noinput = empty($path1) || empty($path2);
110 $listing = array(); -  
111   184  
112 // Generate the diff listing 185 // Generate the diff listing
-   186  
-   187 $relativePath1 = $path1;
-   188 $relativePath2 = $path2;
-   189  
113 $path1 = encodepath(str_replace(DIRECTORY_SEPARATOR, "/", $svnrep->repConfig->path.$path1)); 190 $svnpath1 = encodepath($svnrep->getSvnPath(str_replace(DIRECTORY_SEPARATOR, '/', $path1 ?? '')));
114 $path2 = encodepath(str_replace(DIRECTORY_SEPARATOR, "/", $svnrep->repConfig->path.$path2)); 191 $svnpath2 = encodepath($svnrep->getSvnPath(str_replace(DIRECTORY_SEPARATOR, '/', $path2 ?? '')));
115   192  
116 $debug = false; 193 $debug = false;
117   194  
118 if (!$noinput) 195 if (!$noinput)
119 { 196 {
120 $rawcmd = $config->svn." diff ".$rep->svnParams().quote($path1."@".$rev1)." ".quote($path2."@".$rev2); 197 $cmd = $config->getSvnCommand().$rep->svnCredentials().' diff '.($ignoreWhitespace ? '-x "-w --ignore-eol-style" ' : '').quote($svnpath1.'@'.$rev1).' '.quote($svnpath2.'@'.$rev2);
121 $cmd = quoteCommand($rawcmd, true); -  
122 if ($debug) echo "$cmd\n"; -  
123 } 198 }
124   199  
125 function clearVars() 200 function clearVars()
126 { 201 {
127 global $listing, $index; 202 global $ignoreWhitespace, $listing, $index;
128 203  
129 $listing[$index]["newpath"] = null; 204 if ($ignoreWhitespace && $index > 1)
-   205 {
-   206 $endBlock = false;
-   207 $previous = $index - 1;
130 $listing[$index]["endpath"] = null; 208 if ($listing[$previous]['endpath']) $endBlock = 'newpath';
-   209 else if ($listing[$previous]['enddifflines']) $endBlock = 'difflines';
-   210  
-   211 if ($endBlock !== false)
-   212 {
-   213 // check if block ending at previous contains real diff data
-   214 $i = $previous;
131 $listing[$index]["info"] = null; 215 $containsOnlyEqualDiff = true;
-   216 $addedLines = array();
-   217 $removedLines = array();
-   218 while ($i >= 0 && !$listing[$i - 1][$endBlock])
-   219 {
132 $listing[$index]["diffclass"] = null; 220 $diffclass = $listing[$i - 1]['diffclass'];
-   221  
-   222 if ($diffclass !== 'diffadded' && $diffclass !== 'diffdeleted')
-   223 {
-   224 if ($addedLines !== $removedLines)
-   225 {
133 $listing[$index]["difflines"] = null; 226 $containsOnlyEqualDiff = false;
-   227 break;
-   228 }
-   229 }
-   230  
-   231 if (count($addedLines) > 0 && $addedLines === $removedLines)
-   232 {
-   233 $addedLines = array();
-   234 $removedLines = array();
-   235 }
-   236  
-   237 if ($diffclass === 'diff')
-   238 {
-   239 $i--;
-   240 continue;
-   241 }
-   242  
134 $listing[$index]["enddifflines"] = null; 243 if ($diffclass === null)
-   244 {
135 $listing[$index]["properties"] = null; 245 $containsOnlyEqualDiff = false;
-   246 break;;
136 } 247 }
137   248  
-   249 if ($diffclass === 'diffdeleted')
-   250 {
-   251 if (count($addedLines) <= count($removedLines))
-   252 {
-   253 $containsOnlyEqualDiff = false;
-   254 break;;
-   255 }
-   256  
-   257 array_unshift($removedLines, $listing[$i - 1]['line']);
-   258 $i--;
-   259 continue;
-   260 }
-   261  
-   262 if ($diffclass === 'diffadded')
-   263 {
-   264 if (count($removedLines) > 0)
-   265 {
-   266 $containsOnlyEqualDiff = false;
-   267 break;;
-   268 }
-   269  
-   270 array_unshift($addedLines, $listing[$i - 1]['line']);
-   271 $i--;
-   272 continue;
-   273 }
-   274  
-   275 assert(false);
-   276 }
-   277  
-   278 if ($containsOnlyEqualDiff)
-   279 {
-   280 $containsOnlyEqualDiff = $addedLines === $removedLines;
-   281 }
-   282  
-   283 // remove blocks which only contain diffclass=diff and equal removes and adds
-   284 if ($containsOnlyEqualDiff)
-   285 {
-   286 for ($j = $i - 1; $j < $index; $j++)
-   287 {
-   288 unset($listing[$j]);
-   289 }
-   290  
-   291 $index = $i - 1;
-   292 }
-   293 }
-   294 }
-   295  
-   296 $listvar = &$listing[$index];
-   297 $listvar['newpath'] = null;
-   298 $listvar['endpath'] = null;
-   299 $listvar['info'] = null;
-   300 $listvar['diffclass'] = null;
-   301 $listvar['difflines'] = null;
-   302 $listvar['enddifflines'] = null;
-   303 $listvar['properties'] = null;
-   304 }
-   305  
138 $vars["success"] = false; 306 $vars['success'] = false;
139   307  
140 if (!$noinput) 308 if (!$noinput)
141 { 309 {
-   310 // TODO: Report warning/error if comparison encounters any problems
142 if ($diff = popen($cmd, "r")) 311 if ($diff = popenCommand($cmd, 'r'))
143 { 312 {
-   313 $listing = array();
144 $index = 0; 314 $index = 0;
145 $indiff = false; 315 $indiff = false;
146 $indiffproper = false; 316 $indiffproper = false;
147 $getLine = true; 317 $getLine = true;
148 $node = null; 318 $node = null;
-   319 $bufferedLine = false;
149 320  
150 $vars["success"] = true; 321 $vars['success'] = true;
151 322  
152 while (!feof($diff)) 323 while (!feof($diff))
153 { 324 {
154 if ($getLine) 325 if ($getLine)
-   326 {
-   327 if ($bufferedLine === false)
-   328 {
-   329 $bufferedLine = rtrim(fgets($diff), "\n\r");
-   330 }
-   331  
-   332 $newlineR = strpos($bufferedLine, "\r");
-   333 $newlineN = strpos($bufferedLine, "\n");
-   334 if ($newlineR === false && $newlineN === false)
-   335 {
155 $line = fgets($diff); 336 $line = $bufferedLine;
-   337 $bufferedLine = false;
-   338 }
-   339 else
-   340 {
-   341 $newline = ($newlineR < $newlineN ? $newlineR : $newlineN);
-   342 $line = substr($bufferedLine, 0, $newline);
-   343 $bufferedLine = substr($bufferedLine, $newline + 1);
-   344 }
-   345 }
156 346  
157 clearVars(); 347 clearVars();
158 $getLine = true; 348 $getLine = true;
159 if ($debug) print "Line = '$line'<br />" ; 349 if ($debug) print 'Line = "'.$line.'"<br />';
160 if ($indiff) 350 if ($indiff)
161 { 351 {
162 // If we're in a diff proper, just set up the line 352 // If we're in a diff proper, just set up the line
163 if ($indiffproper) 353 if ($indiffproper)
164 { 354 {
165 if ($line[0] == " " || $line[0] == "+" || $line[0] == "-") 355 if (strlen($line) > 0 && ($line[0] == ' ' || $line[0] == '+' || $line[0] == '-'))
166 { 356 {
-   357 $subline = escape(toOutputEncoding(substr($line, 1)));
-   358 $subline = rtrim($subline, "\n\r");
-   359 $subline = ($subline) ? expandTabs($subline) : '&nbsp;';
-   360 $listvar = &$listing[$index];
-   361 $listvar['line'] = $subline;
-   362  
167 switch ($line[0]) 363 switch ($line[0])
168 { 364 {
169 case " ": 365 case ' ':
170 $listing[$index]["diffclass"] = "diff"; 366 $listvar['diffclass'] = 'diff';
171 $subline = hardspace(replaceEntities(rtrim(substr($line, 1)), $rep)); -  
172 if (empty($subline)) $subline = "&nbsp;"; -  
173 $listing[$index++]["line"] = $subline; -  
174 if ($debug) print "Including as diff: $subline<br />"; 367 if ($debug) print 'Including as diff: '.$subline.'<br />';
175 break; 368 break;
176 369  
177 case "+": 370 case '+':
178 $listing[$index]["diffclass"] = "diffadded"; 371 $listvar['diffclass'] = 'diffadded';
179 $subline = hardspace(replaceEntities(rtrim(substr($line, 1)), $rep)); -  
180 if (empty($subline)) $subline = "&nbsp;"; -  
181 $listing[$index++]["line"] = $subline; -  
182 if ($debug) print "Including as added: $subline<br />"; 372 if ($debug) print 'Including as added: '.$subline.'<br />';
183 break; 373 break;
184 374  
185 case "-": 375 case '-':
186 $listing[$index]["diffclass"] = "diffdeleted"; 376 $listvar['diffclass'] = 'diffdeleted';
187 $subline = hardspace(replaceEntities(rtrim(substr($line, 1)), $rep)); -  
188 if (empty($subline)) $subline = "&nbsp;"; -  
189 $listing[$index++]["line"] = $subline; -  
190 if ($debug) print "Including as removed: $subline<br />"; 377 if ($debug) print 'Including as removed: '.$subline.'<br />';
191 break; 378 break;
192 } 379 }
193 380 $index++;
194 continue; -  
195 } 381 }
196 else 382 else if ($line != '\ No newline at end of file')
197 { 383 {
198 $indiffproper = false; 384 $indiffproper = false;
199 $listing[$index++]["enddifflines"] = true; 385 $listing[$index++]['enddifflines'] = true;
200 $getLine = false; 386 $getLine = false;
201 if ($debug) print "Ending lines<br />"; 387 if ($debug) print 'Ending lines<br />';
202 continue; -  
203 } 388 }
-   389 continue;
204 } 390 }
205 391  
206 // Check for the start of a new diff area 392 // Check for the start of a new diff area
207 if (!strncmp($line, "@@", 2)) 393 if (!strncmp($line, '@@', 2))
208 { 394 {
209 $pos = strpos($line, "+"); 395 $pos = strpos($line, '+');
210 $posline = substr($line, $pos); 396 $posline = substr($line, $pos);
-   397 $sline = 0;
-   398 $eline = 0;
211 sscanf($posline, "+%d,%d", $sline, $eline); 399 sscanf($posline, '+%d,%d', $sline, $eline);
-   400  
212 if ($debug) print "sline = '$sline', eline = '$eline'<br />"; 401 if ($debug) print 'sline = "'.$sline.'", eline = "'.$eline.'"<br />';
-   402  
213 // Check that this isn't a file deletion 403 // Check that this isn't a file deletion
214 if ($sline == 0 && $eline == 0) 404 if ($sline == 0 && $eline == 0)
215 { 405 {
216 $line = fgets($diff); 406 $line = fgets($diff);
217 if ($debug) print "Ignoring: $line<br />" ; 407 if ($debug) print 'Ignoring: "'.$line.'"<br />';
-   408  
218 while ($line[0] == " " || $line[0] == "+" || $line[0] == "-") 409 while ($line && ($line[0] == ' ' || $line[0] == '+' || $line[0] == '-'))
219 { 410 {
220 $line = fgets($diff); 411 $line = fgets($diff);
221 if ($debug) print "Ignoring: $line<br />" ; 412 if ($debug) print 'Ignoring: "'.$line.'"<br />';
222 } 413 }
223 414  
224 $getLine = false; 415 $getLine = false;
225 if ($debug) print "Unignoring previous - marking as deleted<b>"; 416 if ($debug) print 'Unignoring previous - marking as deleted<br />';
226 $listing[$index++]["info"] = $lang["FILEDELETED"]; 417 $listing[$index++]['info'] = $lang['FILEDELETED'];
-   418  
227 } 419 }
228 else 420 else
229 { 421 {
-   422 $listvar = &$listing[$index];
230 $listing[$index++]["difflines"] = $line; 423 $listvar['difflines'] = $line;
-   424 $sline = 0;
-   425 $slen = 0;
-   426 $eline = 0;
-   427 $elen = 0;
-   428 sscanf($line, '@@ -%d,%d +%d,%d @@', $sline, $slen, $eline, $elen);
-   429 $listvar['rev1line'] = $sline;
-   430 $listvar['rev1len'] = $slen;
-   431 $listvar['rev2line'] = $eline;
-   432 $listvar['rev2len'] = $elen;
-   433  
231 $indiffproper = true; 434 $indiffproper = true;
-   435  
-   436 $index++;
232 } 437 }
233 438  
234 continue; 439 continue;
-   440  
235 } 441 }
236 else 442 else
237 { 443 {
238 $indiff = false; 444 $indiff = false;
239 if ($debug) print "Ending diff"; 445 if ($debug) print 'Ending diff';
240 } 446 }
241 } 447 }
242 448  
243 // Check for a new node entry 449 // Check for a new node entry
244 if (strncmp(trim($line), "Index: ", 7) == 0) 450 if (strncmp(trim($line), 'Index: ', 7) == 0)
245 { 451 {
246 // End the current node 452 // End the current node
247 if ($node) 453 if ($node)
248 { 454 {
249 $listing[$index++]["endpath"] = true; 455 $listing[$index++]['endpath'] = true;
250 clearVars(); 456 clearVars();
251 } 457 }
252 458  
253 $node = trim($line); 459 $node = trim(toOutputEncoding($line));
254 $node = substr($node, 7); 460 $node = substr($node, 7);
-   461 if ($node == '' || $node[0] != '/') $node = '/'.$node;
-   462  
-   463 if (substr($path2, -strlen($node)) === $node)
-   464 {
-   465 $absnode = $path2;
-   466 }
-   467 else
-   468 {
-   469 $absnode = $path2;
-   470 if (substr($absnode, -1) == '/') $absnode = substr($absnode, 0, -1);
-   471 $absnode .= $node;
-   472 }
255 473  
-   474 $listvar = &$listing[$index];
256 $listing[$index]["newpath"] = $node; 475 $listvar['newpath'] = escape($absnode);
-   476  
-   477 $listvar['fileurl'] = $config->getURL($rep, $absnode, 'file').'rev='.$rev2;
-   478  
257 if ($debug) echo "Creating node $node<br />"; 479 if ($debug) echo 'Creating node '.$node.'<br />';
258 480  
259 // Skip past the line of ='s 481 // Skip past the line of ='s
260 $line = fgets($diff); 482 $line = fgets($diff);
261 if ($debug) print "Skipping: $line<br />" ; 483 if ($debug) print 'Skipping: '.$line.'<br />';
262 484  
263 // Check for a file addition 485 // Check for a file addition
264 $line = fgets($diff); 486 $line = fgets($diff);
265 if ($debug) print "Examining: $line<br />" ; 487 if ($debug) print 'Examining: '.$line.'<br />';
266 if (strpos($line, "(revision 0)")) 488 if (strpos($line, '(revision 0)'))
-   489 {
267 $listing[$index]["info"] = $lang["FILEADDED"]; 490 $listvar['info'] = $lang['FILEADDED'];
-   491 }
268 492  
269 if (strncmp(trim($line), "Cannot display:", 15) == 0) 493 if (strncmp(trim($line), 'Cannot display:', 15) == 0)
270 { 494 {
271 $index++; 495 $index++;
272 clearVars(); 496 clearVars();
273 $listing[$index++]["info"] = $line; 497 $listing[$index++]['info'] = escape(toOutputEncoding(rtrim($line, "\n\r")));
274 continue; 498 continue;
275 } 499 }
276 500  
277 // Skip second file info 501 // Skip second file info
278 $line = fgets($diff); 502 $line = fgets($diff);
279 if ($debug) print "Skipping: $line<br />" ; 503 if ($debug) print 'Skipping: '.$line.'<br />';
280 504  
281 $indiff = true; 505 $indiff = true;
282 $index++; 506 $index++;
283 507  
284 continue; 508 continue;
285 } 509 }
286 510  
287 if (strncmp(trim($line), "Property changes on: ", 21) == 0) 511 if (strncmp(trim($line), 'Property changes on: ', 21) == 0)
288 { 512 {
289 $propnode = trim($line); 513 $propnode = trim($line);
290 $propnode = substr($propnode, 21); 514 $propnode = substr($propnode, 21);
-   515 if ($propnode == '' || $propnode[0] != '/') $propnode = '/'.$propnode;
291 516  
292 if ($debug) print "Properties on $propnode (cur node $ $node)"; 517 if ($debug) print 'Properties on '.$propnode.' (cur node $ '.$node.')';
293 if ($propnode != $node) 518 if ($propnode != $node)
294 { 519 {
295 if ($node) 520 if ($node)
296 { 521 {
297 $listing[$index++]["endpath"] = true; 522 $listing[$index++]['endpath'] = true;
298 clearVars(); 523 clearVars();
299 } 524 }
300 525  
301 $node = $propnode; 526 $node = $propnode;
302 527  
303 $listing[$index++]["newpath"] = $node; 528 $listing[$index++]['newpath'] = escape(toOutputEncoding($node));
304 clearVars(); 529 clearVars();
305 } 530 }
306 531  
307 $listing[$index++]["properties"] = true; 532 $listing[$index++]['properties'] = true;
308 clearVars(); 533 clearVars();
309 if ($debug) echo "Creating node $node<br />"; 534 if ($debug) echo 'Creating node '.$node.'<br />';
310 535  
311 // Skip the row of underscores 536 // Skip the row of underscores
312 $line = fgets($diff); 537 $line = fgets($diff);
313 if ($debug) print "Skipping: $line<br />" ; 538 if ($debug) print 'Skipping: '.$line.'<br />';
314 539  
315 while ($line = trim(fgets($diff))) 540 while ($line = rtrim(fgets($diff), "\n\r"))
-   541 {
-   542 if (!strncmp(trim($line), 'Index: ', 7))
316 { 543 {
-   544 break;
-   545 }
-   546 if (!strncmp(trim($line), '##', 2) || $line == '\ No newline at end of file')
-   547 {
-   548 continue;
-   549 }
317 $listing[$index++]["info"] = $line; 550 $listing[$index++]['info'] = escape(toOutputEncoding($line));
318 clearVars(); 551 clearVars();
319 } 552 }
-   553 $getLine = false;
320 554  
321 continue; 555 continue;
322 } 556 }
323 557  
324 // Check for error messages 558 // Check for error messages
325 if (strncmp(trim($line), "svn: ", 5) == 0) 559 if (strncmp(trim($line), 'svn: ', 5) == 0)
326 { 560 {
327 $listing[$index++]["info"] = urldecode($line); 561 $listing[$index++]['info'] = urldecode($line);
328 $vars["success"] = false; 562 $vars['success'] = false;
329 continue; 563 continue;
330 } 564 }
331 565  
332 $listing[$index++]["info"] = $line; 566 $listing[$index++]['info'] = escape(toOutputEncoding($line));
-   567
-   568 if (strlen($line) === 0)
-   569 {
-   570 if (!isset($vars['warning']))
-   571 {
-   572 $vars['warning'] = "No changes between revisions";
-   573 }
-   574 }
333 575
334 } 576 }
335 577  
336 if ($node) 578 if ($node)
337 { 579 {
338 clearVars(); 580 clearVars();
339 $listing[$index++]["endpath"] = true; 581 $listing[$index++]['endpath'] = true;
340 } 582 }
341 583  
342 if ($debug) print_r($listing); 584 if ($debug) print_r($listing);
-   585  
-   586 if (!$rep->hasUnrestrictedReadAccess($relativePath1) || !$rep->hasUnrestrictedReadAccess($relativePath2, false))
-   587 {
-   588 // check every item for access and remove it if read access is not allowed
-   589 $restricted = array();
-   590 $inrestricted = false;
-   591 foreach ($listing as $i => $item)
-   592 {
-   593 if ($item['newpath'] !== null)
-   594 {
-   595 $newpath = $item['newpath'];
-   596 $inrestricted = !$rep->hasReadAccess($newpath, false);
-   597 }
-   598  
-   599 if ($inrestricted)
-   600 {
-   601 $restricted[] = $i;
-   602 }
-   603  
-   604 if ($item['endpath'] !== null)
-   605 {
-   606 $inrestricted = false;
343 } 607 }
344 } 608 }
345   609  
346 $vars["version"] = $version; 610 foreach ($restricted as $i)
-   611 {
-   612 unset($listing[$i]);
-   613 }
347   614  
348 if (!$rep->hasUnrestrictedReadAccess($path1) || !$rep->hasUnrestrictedReadAccess($path2, false)) 615 if (count($restricted) && !count($listing))
-   616 {
349 $vars["noaccess"] = true; 617 $vars['error'] = $lang['NOACCESS'];
-   618 sendHeaderForbidden();
-   619 }
-   620 }
350   621  
351 parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing); -  
352 parseTemplate($rep->getTemplatePath()."compare.tmpl", $vars, $listing); -  
353 parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing); 622 pclose($diff);
-   623 }
-   624 }
354 625  
355 ?> -  
-   626 renderTemplate('compare');