From aca03bd78aff687c9b4aec4679a10d55b63eac29 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 27 Aug 2005 21:30:22 +0000 Subject: [PATCH] - browse.php basics in place - added SVNLib --- browse.php | 25 +++++++ includes/init.php | 5 ++ includes/paths.php | 6 +- includes/repository.php | 4 +- includes/svnlib.php | 150 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 5 deletions(-) diff --git a/browse.php b/browse.php index 22073f8..ecdd9fc 100644 --- a/browse.php +++ b/browse.php @@ -16,7 +16,32 @@ $path = $viewsvn->paths->parse(); $repos = $viewsvn->paths->fetch_repos($path); $relpath = $viewsvn->paths->fetch_path($path); +$listing = $viewsvn->svn->ls($repos, $relpath, 0); +print_r($listing); + +echo ''; /*=====================================================================*\ || ################################################################### diff --git a/includes/init.php b/includes/init.php index 4452f95..2856655 100644 --- a/includes/init.php +++ b/includes/init.php @@ -60,6 +60,11 @@ $viewsvn->repos =& new Repository($repository, $iscontainer); require_once('./includes/paths.php'); $viewsvn->paths =& new Paths($pathtype); +// ################################################################### +// initialize SVN +require_once('./includes/svnlib.php'); +$viewsvn->svn =& new SVNLib($svnpath); + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/includes/paths.php b/includes/paths.php index 3d8e593..877de03 100644 --- a/includes/paths.php +++ b/includes/paths.php @@ -74,7 +74,7 @@ class Paths // advanced path system else if ($this->type == 2) { - return $url[0] . '/' . $viewsvn->fetch_sourcepath($addpath) . ($url[1] ? '?' . $url[1] : ''); + return $url[0] . ($addpath{0} != '/' ? '/' : '') . $viewsvn->fetch_sourcepath($addpath) . ($url[1] ? '?' . $url[1] : ''); } } @@ -98,7 +98,7 @@ class Paths // advanced path system else if ($this->type == 2) { - if ($_SERVER['PATH_INFO']) + if (@$_SERVER['PATH_INFO']) { $path = $viewsvn->sanitize($_SERVER['PATH_INFO']); } @@ -190,7 +190,7 @@ class Paths */ function sanitize($path) { - return preg_replace('#[^a-z0-9\.]*#i', '', $path); + return preg_replace('#[^a-z0-9\./\-]*#i', '', $path); } } diff --git a/includes/repository.php b/includes/repository.php index 82d77aa..7d93339 100644 --- a/includes/repository.php +++ b/includes/repository.php @@ -117,11 +117,11 @@ class Repository if ($this->container) { - return $this->path . $repository; + return 'file://' . $this->path . $repository; } else { - return $this->path; + return 'file://' . $this->path; } } diff --git a/includes/svnlib.php b/includes/svnlib.php index 1e01b16..ce6dc6c 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -10,6 +10,156 @@ || ################################################################### || \*=====================================================================*/ +/** +* Command line interface with the SVN commands +* +* @package ViewSVN +*/ + +/** +* Interacts with the command line subsystem to +* access SVN information +* +* @package ViewSVN +* @version $Id$ +*/ +class SVNLib +{ + /** + * Path to the SVN binary + * @var string + */ + var $svnpath; + + /** + * Constructor: validate SVN path + * + * @param string Path to SVN binary + */ + function SVNLib($svnpath) + { + global $viewsvn; + + $this->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); + + 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: 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$ -- 2.22.5