controller =& $controller; $this->svnpath =& $this->controller->xquery->cmd($this->controller->registry->svnpath); $access = $this->controller->xquery->exec($this->svnpath . ' --version'); if (!$access) { $this->controller->registry->trigger->error($this->controller->registry->lang->string('The SVN binary could not be located')); } if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0]))) { $this->controller->registry->trigger->error($this->controller->registry->lang->string('The SVN binary does not appear to be valid (it failed our tests)')); } } /** * Executes the SVN binary * * @access private * * @param string Command * * @return array Output */ function svn($command) { $output = $this->controller->xquery->exec($this->svnpath . ' ' . $command . ' 2>&1'); // make sure that we keep escaped chars //$output = str_replace(array('\t', '\n', '\r'), array('\\\t', '\\\n', '\\\r'), $output); //$output = preg_replace('#\\\(.)#', '\\\\\\\\' . '\1', $output); //$output = str_replace('\\', '\\\\', $output); $temp = implode("\n", $output); if (strpos($temp, '(apr' . '_err=') !== false) { $this->controller->registry->trigger->error(nl2br($temp)); } return $output; } /** * 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 . ' ' . $repospath . $path . '@' . $revision); } /** * 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: diff * * @access protected * * @param string Repository * @param string Path * @param integer Lower revision * @param integer Higher revision * * @return array Lines of diff output */ function diff($repos, $path, $lorev, $hirev) { global $viewsvn; $hirev = $this->rev($hirev); $lorev = $this->rev($lorev); if ($lorev == 'HEAD') { $lorev = 1; } if (is_integer($hirev) AND is_integer($lorev)) { if ($lorev > $hirev) { $lorev = $hirev - 1; } if ($lorev == $hirev) { $lorev = 0; } } $repospath = $viewsvn->repos->fetch_path($repos, false); return $this->svn('diff -r' . $lorev . ':' . $hirev . ' ' . $repospath . $path); } /** * 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; } if ($lorev == $hirev) { $lorev = 0; } } $repospath = $viewsvn->repos->fetch_path($repos, false); return $this->svn('log -v -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; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>