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))
189 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
191 return $this->svn('log -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path);
195 * SVN Wrapper: ls (list)
199 * @param string Repository
201 * @param integer Revision
203 * @return array Lines of list output
205 function ls($repos, $path, $revision)
207 return $this->std('list', $repos, $path, $revision);
211 * Generates a clean revision number
215 * @param integer Revision number
217 * @return mixed Cleaned revision or HEAD
219 function rev($revision)
221 if (($revision = intval($revision)) < 1)
230 * Annotation/blame system; constructs an array
231 * that is ready for output
239 * Array of blame information
242 var $blame = array();
245 * Raw "svn blame" output
250 * Constructor: create blame and store data
252 * @param string Repository
254 * @param integer Revision
256 function SVNBlame($repos, $path, $revision)
260 $this->rawoutput
= $viewsvn->svn
->blame($repos, $path, $revision);
265 * Returns blame for display
269 * @return array Blame data
277 * Parses the blame data
285 foreach ($this->rawoutput
AS $line)
287 if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
289 $this->blame
[] = array(
290 'rev' => $matches[1],
291 'author' => $matches[2],
292 'line' => $matches[3],
293 'lineno' => $lineno++
297 else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
299 $this->blame
[] = array(
300 'rev' => $matches[1],
301 'author' => $matches[2],
303 'lineno' => $lineno++
311 * Log management system; creates a complex list
312 * of SVN log information
326 * Raw "svn log" output
332 * Constructor: create log store for the given file
334 * @param string Repository
336 * @param integer Lower revision
337 * @param integer Higher revision
339 function SVNLog($repos, $path, $lorev, $hirev)
343 $this->rawoutput
= $viewsvn->svn
->log($repos, $path, $lorev, $hirev);
348 * Returns logs for display
352 * @return array Log data
360 * Splits up the raw output into a usable log
368 for ($i = 1; $i <= count($this->rawoutput
) - 1; $i++
)
370 $line = $this->rawoutput
["$i"];
372 if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
374 if (isset($this->logs
["$lastrev"]))
376 $this->logs
["$lastrev"]['message'] = $this->strip_last_line($this->logs
["$lastrev"]['message']);
379 $this->logs
["$matches[1]"] = array(
380 'rev' => $matches[1],
381 'author' => $matches[2],
382 'date' => $matches[3],
383 'timezone' => $matches[4],
384 'lines' => $matches[6],
388 $lastrev = $matches[1];
392 $this->logs
["$lastrev"]['message'] .= $line . "\n";
396 if (isset($this->logs
["$lastrev"]))
398 $this->logs
["$lastrev"]['message'] = $this->strip_last_line($this->logs
["$lastrev"]['message']);
403 * Trims the last dash line off a message
407 * @param string Message with annoying-ass line
409 * @return string Clean string
411 function strip_last_line($string)
413 return trim(preg_replace("#\n(.*?)\n$#", '', $string));
417 /*=====================================================================*\
418 || ###################################################################
421 || ###################################################################
422 \*=====================================================================*/