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 * Executes the SVN binary
63 * @param string Command
65 * @return array Output
67 function svn($command)
71 return $viewsvn->shell
->exec($this->svnpath
. ' ' . $command . ' 2>&1');
75 * SVN Wrapper: standard command system
79 * @param string SVN command
80 * @param string Repository
82 * @param integer Revision
84 * @return array Lines of output
86 function std($command, $repos, $path, $revision)
90 $revision = $this->rev($revision);
91 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
93 return $this->svn($command . ' -r' . $revision . ' ' . $repospath . $path);
101 * @param string Repository
103 * @param integer Revision
105 * @return array Lines of blame output
107 function blame($repos, $path, $revision)
109 return $this->std('blame', $repos, $path, $revision);
117 * @param string Repository
119 * @param integer Revision
121 * @return array Lines of cat output
123 function cat($repos, $path, $revision)
125 return $this->std('cat', $repos, $path, $revision);
133 * @param string Repository
135 * @param integer Lower revision
136 * @param integer Higher revision
138 * @return array Lines of log output
140 function log($repos, $path, $lorev, $hirev)
144 $hirev = $this->rev($hirev);
145 $lorev = $this->rev($hirev);
146 if ($lorev == 'HEAD')
151 if (is_integer($hirev) AND is_integer($lorev))
159 $repospath = $viewsvn->repos
->fetch_path($repos, false
);
161 return $this->svn('log -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path);
165 * SVN Wrapper: ls (list)
169 * @param string Repository
171 * @param integer Revision
173 * @return array Lines of list output
175 function ls($repos, $path, $revision)
177 return $this->std('list', $repos, $path, $revision);
181 * Generates a clean revision number
185 * @param integer Revision number
187 * @return mixed Cleaned revision or HEAD
189 function rev($revision)
191 if (($revision = intval($revision)) < 1)
200 * Annotation/blame system; constructs an array
201 * that is ready for output
209 * Array of blame information
212 var $blame = array();
215 * Raw "svn blame" output
220 * Constructor: create blame and store data
222 * @param string Repository
224 * @param integer Revision
226 function SVNBlame($repos, $path, $revision)
230 $this->rawoutput
= $viewsvn->svn
->blame($repos, $path, $revision);
235 * Returns blame for display
239 * @return array Blame data
247 * Parses the blame data
255 foreach ($this->rawoutput
AS $line)
257 if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
259 $this->blame
[] = array(
260 'rev' => $matches[1],
261 'author' => $matches[2],
262 'line' => $matches[3],
263 'lineno' => $lineno++
267 else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
269 $this->blame
[] = array(
270 'rev' => $matches[1],
271 'author' => $matches[2],
273 'lineno' => $lineno++
281 * Log management system; creates a complex list
282 * of SVN log information
296 * Raw "svn log" output
302 * Constructor: create log store for the given file
304 * @param string Repository
306 * @param integer Lower revision
307 * @param integer Higher revision
309 function SVNLog($repos, $path, $lorev, $hirev)
313 $this->rawoutput
= $viewsvn->svn
->log($repos, $path, $lorev, $hirev);
318 * Returns logs for display
322 * @return array Log data
330 * Splits up the raw output into a usable log
338 for ($i = 1; $i <= count($this->rawoutput
) - 1; $i++
)
340 $line = $this->rawoutput
["$i"];
342 if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
344 if (isset($this->logs
["$lastrev"]))
346 $this->logs
["$lastrev"]['message'] = $this->strip_last_line($this->logs
["$lastrev"]['message']);
349 $this->logs
["$matches[1]"] = array(
350 'rev' => $matches[1],
351 'author' => $matches[2],
352 'date' => $matches[3],
353 'timezone' => $matches[4],
354 'lines' => $matches[6],
358 $lastrev = $matches[1];
362 $this->logs
["$lastrev"]['message'] .= $line . "\n";
366 if (isset($this->logs
["$lastrev"]))
368 $this->logs
["$lastrev"]['message'] = $this->strip_last_line($this->logs
["$lastrev"]['message']);
373 * Trims the last dash line off a message
377 * @param string Message with annoying-ass line
379 * @return string Clean string
381 function strip_last_line($string)
383 return trim(preg_replace("#\n(.*?)\n$#", '', $string));
387 /*=====================================================================*\
388 || ###################################################################
391 || ###################################################################
392 \*=====================================================================*/