svnpath = $viewsvn->shell->cmd($svnpath); $access = $viewsvn->shell->exec($this->svnpath . ' --version'); if (!$access) { $viewsvn->trigger->error('svn binary could not be found'); } if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0]))) { $viewsvn->trigger->error('svn binary does not pass test'); } } /** * Executes the SVN binary * * @access private * * @param string Command * * @return array Output */ function svn($command) { global $viewsvn; return $viewsvn->shell->exec($this->svnpath . ' ' . $command . ' 2>&1'); } /** * SVN Wrapper: standard command system * * @access private * * @param string SVN command * @param string Repository * @param string Path * @param integer Revision * * @return array Lines of output */ function std($command, $repos, $path, $revision) { global $viewsvn; $revision = $this->rev($revision); $repospath = $viewsvn->repos->fetch_path($repos, false); return $this->svn($command . ' -r' . $revision . ' ' . $repospath . $path); } /** * SVN Wrapper: blame * * @access protected * * @param string Repository * @param string Path * @param integer Revision * * @return array Lines of blame output */ function blame($repos, $path, $revision) { return $this->std('blame', $repos, $path, $revision); } /** * SVN Wrapper: cat * * @access protected * * @param string Repository * @param string Path * @param integer Revision * * @return array Lines of cat output */ function cat($repos, $path, $revision) { return $this->std('cat', $repos, $path, $revision); } /** * SVN Wrapper: log * * @access protected * * @param string Repository * @param string Path * @param integer Lower revision * @param integer Higher revision * * @return array Lines of log output */ function log($repos, $path, $lorev, $hirev) { global $viewsvn; $hirev = $this->rev($hirev); $lorev = $this->rev($hirev); if ($lorev == 'HEAD') { $lorev = 0; } if (is_integer($hirev) AND is_integer($lorev)) { if ($lorev > $hirev) { $lorev = $hirev - 1; } } $repospath = $viewsvn->repos->fetch_path($repos, false); return $this->svn('log -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path); } /** * SVN Wrapper: ls (list) * * @access protected * * @param string Repository * @param string Path * @param integer Revision * * @return array Lines of list output */ function ls($repos, $path, $revision) { return $this->std('list', $repos, $path, $revision); } /** * Generates a clean revision number * * @access public * * @param integer Revision number * * @return mixed Cleaned revision or HEAD */ function rev($revision) { if (($revision = intval($revision)) < 1) { $revision = 'HEAD'; } return $revision; } } /** * Log management system; creates a complex list * of SVN log information * * @package ViewSVN * @version $Id$ */ class SVNLog { /** * Array of logs * @var array */ var $logs = array(); /** * Raw "svn log" output * @var array */ var $rawoutput; /** * Constructor: create log store for the given file * * @param string Repository * @param string Path * @param integer Lower revision * @param integer Higher revision */ function SVNLog($repos, $path, $lorev, $hirev) { global $viewsvn; $this->rawoutput = $viewsvn->svn->log($repos, $path, $lorev, $hirev); $this->process(); } /** * Returns logs for display * * @access public * * @return array Log data */ function fetch() { return $this->logs; } /** * Splits up the raw output into a usable log * * @access private */ function process() { $lastrev = 0; for ($i = 1; $i <= count($this->rawoutput) - 1; $i++) { $line = $this->rawoutput["$i"]; if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches)) { if (isset($this->logs["$lastrev"])) { $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']); } $this->logs["$matches[1]"] = array( 'rev' => $matches[1], 'author' => $matches[2], 'date' => $matches[3], 'timezone' => $matches[4], 'lines' => $matches[6], 'message' => '' ); $lastrev = $matches[1]; } else { $this->logs["$lastrev"]['message'] .= $line . "\n"; } } if (isset($this->logs["$lastrev"])) { $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']); } } /** * Trims the last dash line off a message * * @access private * * @param string Message with annoying-ass line * * @return string Clean string */ function strip_last_line($string) { return trim(preg_replace("#\n(.*?)\n$#", '', $string)); } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>