jablonka.czprosek.czf

websvn

Subversion Repositories:
[/] [comp.php] - Blame information for rev 1

 

Line No. Rev Author Line
11simandl<?php
2// WebSVN - Subversion repository viewing via the web using PHP
3// Copyright (C) 2004-2006 Tim Armes
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18//
19// --
20//
21// comp.php
22//
23// Compare two paths using "svn diff"
24//
25 
26require_once("include/setup.php");
27require_once("include/svnlook.php");
28require_once("include/utils.php");
29require_once("include/template.php");
30 
31function checkRevision($rev) {
32 if (is_numeric($rev) && ((int)$rev > 0)) {
33 return $rev;
34 }
35 
36 $rev = strtoupper($rev);
37 
38 switch($rev) {
39 case "HEAD":
40 // fall through
41 case "PREV":
42 // fall through
43 case "COMMITTED":
44 return $rev;
45 }
46 
47 return "HEAD";
48}
49 
50$svnrep = new SVNRepository($rep);
51 
52// Retrieve the request information
53$path1 = @$_REQUEST["compare"][0];
54$path2 = @$_REQUEST["compare"][1];
55$rev1 = (int)@$_REQUEST["compare_rev"][0];
56$rev2 = (int)@$_REQUEST["compare_rev"][1];
57 
58// Some page links put the revision with the path...
59if (strpos($path1, "@")) list($path1, $rev1) = explode("@", $path1);
60if (strpos($path2, "@")) list($path2, $rev2) = explode("@", $path2);
61 
62$rev1 = checkRevision($rev1);
63$rev2 = checkRevision($rev2);
64 
65// Choose a sensible comparison order unless told not to
66if (!@$_REQUEST["manualorder"] && is_numeric($rev1) && is_numeric($rev2)) {
67 if ($rev1 > $rev2) {
68 $temppath = $path1;
69 $temprev = $rev1;
70 
71 $path1 = $path2;
72 $rev1 = $rev2;
73 
74 $path2 = $temppath;
75 $rev2 = $temprev;
76 }
77}
78 
79$vars['indexurl'] = $config->getURL($rep, '', 'index');
80$vars['repurl'] = $config->getURL($rep, '', 'dir');
81 
82$url = $config->getURL($rep, "/", "comp");
83$vars["revlink"] = "<a href=\"${url}compare%5B%5D=".urlencode($path2)."@$rev2&amp;compare%5B%5D=".urlencode($path1)."@$rev1&amp;manualorder=1\">${lang["REVCOMP"]}</a>";
84 
85if ($rev1 == 0) $rev1 = "HEAD";
86if ($rev2 == 0) $rev2 = "HEAD";
87 
88$vars["repname"] = $rep->getDisplayName();
89$vars["action"] = $lang["PATHCOMPARISON"];
90$vars["compare_form"] = "<form action=\"$url\" method=\"post\">";
91$vars["compare_path1input"] = "<input type=\"text\" size=\"40\" name=\"compare[0]\" value=\"".htmlentities($path1, ENT_QUOTES, 'UTF-8')."\" />";
92$vars["compare_rev1input"] = "<input type=\"text\" size=\"5\" name=\"compare_rev[0]\" value=\"$rev1\" />";
93$vars["compare_path2input"] = "<input type=\"text\" size=\"40\" name=\"compare[1]\" value=\"".htmlentities($path2, ENT_QUOTES, 'UTF-8')."\" />";
94$vars["compare_rev2input"] = "<input type=\"text\" size=\"5\" name=\"compare_rev[1]\" value=\"$rev2\" />";
95$vars["compare_submit"] = "<input name=\"comparesubmit\" type=\"submit\" value=\"${lang["COMPAREPATHS"]}\" />";
96$vars["compare_hidden"] = "<input type=\"hidden\" name=\"op\" value=\"comp\" /><input type=\"hidden\" name=\"manualorder\" value=\"1\" />";
97$vars["compare_endform"] = "</form>";
98 
99// safe paths are a hack for fixing XSS sploit
100$vars["path1"] = htmlentities($path1, ENT_QUOTES, 'UTF-8');
101$vars['safepath1'] = htmlentities($path1, ENT_QUOTES, 'UTF-8');
102$vars["path2"] = htmlentities($path2, ENT_QUOTES, 'UTF-8');
103$vars['safepath2'] = htmlentities($path2, ENT_QUOTES, 'UTF-8');
104 
105$vars["rev1"] = $rev1;
106$vars["rev2"] = $rev2;
107 
108$noinput = empty($path1) || empty($path2);
109$listing = array();
110 
111// Generate the diff listing
112 
113$relativePath1 = $path1;
114$relativePath2 = $path2;
115 
116$path1 = encodepath(str_replace(DIRECTORY_SEPARATOR, "/", $svnrep->repConfig->path.$path1));
117$path2 = encodepath(str_replace(DIRECTORY_SEPARATOR, "/", $svnrep->repConfig->path.$path2));
118 
119$debug = false;
120 
121if (!$noinput) {
122 $rawcmd = $config->svn." diff ".$rep->svnParams().quote($path1."@".$rev1)." ".quote($path2."@".$rev2);
123 $cmd = quoteCommand($rawcmd);
124 if ($debug) echo "$cmd\n";
125}
126 
127function clearVars() {
128 global $listing, $index;
129 
130 $listing[$index]["newpath"] = null;
131 $listing[$index]["endpath"] = null;
132 $listing[$index]["info"] = null;
133 $listing[$index]["diffclass"] = null;
134 $listing[$index]["difflines"] = null;
135 $listing[$index]["enddifflines"] = null;
136 $listing[$index]["properties"] = null;
137}
138 
139$vars["success"] = false;
140 
141if (!$noinput) {
142 if ($diff = popen($cmd, "r")) {
143 $index = 0;
144 $indiff = false;
145 $indiffproper = false;
146 $getLine = true;
147 $node = null;
148 $bufferedLine = false;
149 
150 $vars["success"] = true;
151 
152 while (!feof($diff)) {
153 if ($getLine) {
154 if ($bufferedLine === false) {
155 $bufferedLine = rtrim(fgets($diff), "\r\n");
156 }
157 $newlineR = strpos($bufferedLine, "\r");
158 $newlineN = strpos($bufferedLine, "\n");
159 if ($newlineR === false && $newlineN === false) {
160 $line = $bufferedLine;
161 $bufferedLine = false;
162 } else {
163 $newline = ($newlineR < $newlineN ? $newlineR : $newlineN);
164 $line = substr($bufferedLine, 0, $newline);
165 $bufferedLine = substr($bufferedLine, $newline + 1);
166 }
167 }
168 
169 clearVars();
170 $getLine = true;
171 if ($debug) print "Line = '$line'<br />";
172 if ($indiff) {
173 // If we're in a diff proper, just set up the line
174 if ($indiffproper) {
175 if (strlen($line) > 0 && ($line[0] == " " || $line[0] == "+" || $line[0] == "-")) {
176 $subline = replaceEntities(substr($line, 1), $rep);
177 if (empty($subline)) $subline = "&nbsp;";
178 $subline = hardspace($subline);
179 $listing[$index]["line"] = $subline;
180 
181 switch ($line[0]) {
182 case " ":
183 $listing[$index]["diffclass"] = "diff";
184 if ($debug) print "Including as diff: $subline<br />";
185 break;
186 
187 case "+":
188 $listing[$index]["diffclass"] = "diffadded";
189 if ($debug) print "Including as added: $subline<br />";
190 break;
191 
192 case "-":
193 $listing[$index]["diffclass"] = "diffdeleted";
194 if ($debug) print "Including as removed: $subline<br />";
195 break;
196 }
197 
198 $index++;
199 
200 continue;
201 
202 } else if ($line == '\ No newline at end of file') {
203 continue;
204 
205 } else {
206 $indiffproper = false;
207 $listing[$index++]["enddifflines"] = true;
208 $getLine = false;
209 if ($debug) print "Ending lines<br />";
210 continue;
211 }
212 }
213 
214 // Check for the start of a new diff area
215 if (!strncmp($line, "@@", 2)) {
216 $pos = strpos($line, "+");
217 $posline = substr($line, $pos);
218 sscanf($posline, "+%d,%d", $sline, $eline);
219 if ($debug) print "sline = '$sline', eline = '$eline'<br />";
220 // Check that this isn't a file deletion
221 if ($sline == 0 && $eline == 0) {
222 $line = fgets($diff);
223 if ($debug) print "Ignoring: $line<br />" ;
224 while ($line[0] == " " || $line[0] == "+" || $line[0] == "-") {
225 $line = fgets($diff);
226 if ($debug) print "Ignoring: $line<br />" ;
227 }
228 
229 $getLine = false;
230 if ($debug) print "Unignoring previous - marking as deleted<b>";
231 $listing[$index++]["info"] = $lang["FILEDELETED"];
232 
233 } else {
234 $listing[$index]["difflines"] = $line;
235 sscanf($line, "@@ -%d,%d +%d,%d @@", $sline, $slen, $eline, $elen);
236 $listing[$index]["rev1line"] = $sline;
237 $listing[$index]["rev1len"] = $slen;
238 $listing[$index]["rev2line"] = $eline;
239 $listing[$index]["rev2len"] = $elen;
240 
241 $indiffproper = true;
242 
243 $index++;
244 }
245 
246 continue;
247 
248 } else {
249 $indiff = false;
250 if ($debug) print "Ending diff";
251 }
252 }
253 
254 // Check for a new node entry
255 if (strncmp(trim($line), "Index: ", 7) == 0) {
256 // End the current node
257 if ($node) {
258 $listing[$index++]["endpath"] = true;
259 clearVars();
260 }
261 
262 $node = trim($line);
263 $node = substr($node, 7);
264 if ($node == '' || $node{0} != '/') $node = '/'.$node;
265 
266 $listing[$index]["newpath"] = $node;
267 
268 $listing[$index]["fileurl"] = $config->getURL($rep, $node, "file").'rev='.$rev2;
269 
270 if ($debug) echo "Creating node $node<br />";
271 
272 // Skip past the line of ='s
273 $line = fgets($diff);
274 if ($debug) print "Skipping: $line<br />" ;
275 
276 // Check for a file addition
277 $line = fgets($diff);
278 if ($debug) print "Examining: $line<br />" ;
279 if (strpos($line, "(revision 0)")) {
280 $listing[$index]["info"] = $lang["FILEADDED"];
281 }
282 
283 if (strncmp(trim($line), "Cannot display:", 15) == 0) {
284 $index++;
285 clearVars();
286 $listing[$index++]["info"] = $line;
287 continue;
288 }
289 
290 // Skip second file info
291 $line = fgets($diff);
292 if ($debug) print "Skipping: $line<br />" ;
293 
294 $indiff = true;
295 $index++;
296 
297 continue;
298 }
299 
300 if (strncmp(trim($line), "Property changes on: ", 21) == 0) {
301 $propnode = trim($line);
302 $propnode = substr($propnode, 21);
303 
304 if ($debug) print "Properties on $propnode (cur node $ $node)";
305 if ($propnode != $node) {
306 if ($node) {
307 $listing[$index++]["endpath"] = true;
308 clearVars();
309 }
310 
311 $node = $propnode;
312 
313 $listing[$index++]["newpath"] = $node;
314 clearVars();
315 }
316 
317 $listing[$index++]["properties"] = true;
318 clearVars();
319 if ($debug) echo "Creating node $node<br />";
320 
321 // Skip the row of underscores
322 $line = fgets($diff);
323 if ($debug) print "Skipping: $line<br />" ;
324 
325 while ($line = trim(fgets($diff))) {
326 $listing[$index++]["info"] = $line;
327 clearVars();
328 }
329 
330 continue;
331 }
332 
333 // Check for error messages
334 if (strncmp(trim($line), "svn: ", 5) == 0) {
335 $listing[$index++]["info"] = urldecode($line);
336 $vars["success"] = false;
337 continue;
338 }
339 
340 $listing[$index++]["info"] = $line;
341 }
342 
343 if ($node) {
344 clearVars();
345 $listing[$index++]["endpath"] = true;
346 }
347 
348 if ($debug) print_r($listing);
349 
350 pclose($diff);
351 }
352}
353 
354$vars["version"] = $version;
355 
356if (!$rep->hasUnrestrictedReadAccess($relativePath1) || !$rep->hasUnrestrictedReadAccess($relativePath2, false)) {
357 $vars["noaccess"] = true;
358}
359 
360parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing);
361parseTemplate($rep->getTemplatePath()."compare.tmpl", $vars, $listing);
362parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing);

Powered by WebSVN 2.2.1