2 /*=====================================================================*\
3 || ################################################################### ||
4 || # ViewSVN [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
14 * Command line interface with the SVN commands
20 * Interacts with the command line subsystem to
21 * access SVN information
29 * Path to the SVN binary
35 * Constructor: validate SVN path
37 * @param string Path to SVN binary
39 function SVNLib($svnpath)
43 $this->svnpath
= $viewsvn->shell
->cmd($svnpath);
45 $access = $viewsvn->shell
->exec($this->svnpath
. ' --version');
49 $viewsvn->trigger
->error('svn binary could not be found');
52 if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
54 $viewsvn->trigger
->error('svn binary does not pass test');
59 * Prepares data for output
63 * @param string Standard data
65 * @return string Output-ready data
67 function format($string)
70 $string = htmlspecialchars($string);
73 $string = str_replace("\t", ' ', $string);
76 $string = str_replace(' ', ' ', $string);
79 $string = nl2br($string);
85 * Executes the SVN binary
89 * @param string Command
91 * @return array Output
93 function svn($command)
97 return $viewsvn->shell
->exec($this->svnpath
. ' ' . $command . ' 2>&1');
101 * SVN Wrapper: standard command system
105 * @param string SVN command
106 * @param string Repository
108 * @param integer Revision
110 * @return array Lines of output
112 function std($command, $repos, $path, $revision)
116 $revision = $this->rev($revision);
117 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
119 return $this->svn($command . ' -r' . $revision . ' ' . $repospath . $path);
127 * @param string Repository
129 * @param integer Revision
131 * @return array Lines of blame output
133 function blame($repos, $path, $revision)
135 return $this->std('blame', $repos, $path, $revision);
143 * @param string Repository
145 * @param integer Revision
147 * @return array Lines of cat output
149 function cat($repos, $path, $revision)
153 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
155 return $this->svn('cat ' . $repospath . $path . '@' . $revision);
163 * @param string Repository
165 * @param integer Lower revision
166 * @param integer Higher revision
168 * @return array Lines of log output
170 function log($repos, $path, $lorev, $hirev)
174 $hirev = $this->rev($hirev);
175 $lorev = $this->rev($hirev);
176 if ($lorev == 'HEAD')
181 if (is_integer($hirev) AND is_integer($lorev))
187 if ($lorev == $hirev)
193 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
195 return $this->svn('log -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path);
199 * SVN Wrapper: ls (list)
203 * @param string Repository
205 * @param integer Revision
207 * @return array Lines of list output
209 function ls($repos, $path, $revision)
211 return $this->std('list', $repos, $path, $revision);
215 * Generates a clean revision number
219 * @param integer Revision number
221 * @return mixed Cleaned revision or HEAD
223 function rev($revision)
225 if (($revision = intval($revision)) < 1)
234 * Annotation/blame system; constructs an array
235 * that is ready for output
243 * Array of blame information
246 var $blame = array();
249 * Raw "svn blame" output
254 * Constructor: create blame and store data
256 * @param string Repository
258 * @param integer Revision
260 function SVNBlame($repos, $path, $revision)
264 $this->rawoutput
= $viewsvn->svn
->blame($repos, $path, $revision);
269 * Returns blame for display
273 * @return array Blame data
281 * Parses the blame data
289 foreach ($this->rawoutput
AS $line)
291 if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
293 $this->blame
[] = array(
294 'rev' => $matches[1],
295 'author' => $matches[2],
296 'line' => $matches[3],
297 'lineno' => $lineno++
301 else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
303 $this->blame
[] = array(
304 'rev' => $matches[1],
305 'author' => $matches[2],
307 'lineno' => $lineno++
315 * Log management system; creates a complex list
316 * of SVN log information
330 * Raw "svn log" output
336 * Constructor: create log store for the given file
338 * @param string Repository
340 * @param integer Lower revision
341 * @param integer Higher revision
343 function SVNLog($repos, $path, $lorev, $hirev)
347 $this->rawoutput
= $viewsvn->svn
->log($repos, $path, $lorev, $hirev);
352 * Returns logs for display
356 * @return array Log data
364 * Splits up the raw output into a usable log
372 for ($i = 1; $i <= count($this->rawoutput
) - 1; $i++
)
374 $line = $this->rawoutput
["$i"];
376 if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
378 if (isset($this->logs
["$lastrev"]))
380 $this->logs
["$lastrev"]['message'] = $this->strip_last_line($this->logs
["$lastrev"]['message']);
383 $this->logs
["$matches[1]"] = array(
384 'rev' => $matches[1],
385 'author' => $matches[2],
386 'date' => $matches[3],
387 'timezone' => $matches[4],
388 'lines' => $matches[6],
392 $lastrev = $matches[1];
396 $this->logs
["$lastrev"]['message'] .= $line . "\n";
400 if (isset($this->logs
["$lastrev"]))
402 $this->logs
["$lastrev"]['message'] = $this->strip_last_line($this->logs
["$lastrev"]['message']);
407 * Trims the last dash line off a message
411 * @param string Message with annoying-ass line
413 * @return string Clean string
415 function strip_last_line($string)
417 return trim(preg_replace("#\n(.*?)\n$#", '', $string));
421 /*=====================================================================*\
422 || ###################################################################
425 || ###################################################################
426 \*=====================================================================*/