From 985ac8eba6d18eea954c55da74b78f8dbe549f2e Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 10 Apr 2007 05:27:14 +0000 Subject: [PATCH] Repository can now take in an array of repositories to include to explicitly allow only certain repositories in a container path --- includes/config.php.new | 8 ++++- includes/init.php | 2 +- includes/repository.php | 66 ++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/includes/config.php.new b/includes/config.php.new index e51b961..592c6d8 100644 --- a/includes/config.php.new +++ b/includes/config.php.new @@ -23,7 +23,8 @@ // ///////////////////////// REPOSITORY PATH // ------------------------------------------------------------------- // The path to your repository or the parent-path for a directory of -// repositories +// repositories. This can also be an array to specify individual +// repository paths. $conf['repository']['path'] = '/home/svn/repos/'; // ################################################################### @@ -32,6 +33,11 @@ $conf['repository']['path'] = '/home/svn/repos/'; // Set this to TRUE if the above path is actually a parent-path $conf['repository']['iscontainer'] = false; +// Repository names to include in the container. If this array is empty, +// all repositories will be added, otherwise it will only be the ones +// in the array. +$conf['repository']['include'] = array(); + // ################################################################### // ///////////////////////// WEB PATH // ------------------------------------------------------------------- diff --git a/includes/init.php b/includes/init.php index ba393ac..1f9a911 100644 --- a/includes/init.php +++ b/includes/init.php @@ -67,7 +67,7 @@ $viewsvn->trigger =& new Imaginary(); // ################################################################### // setup repository require_once('./includes/repository.php'); -BSRegister::Register('repos', $repos = new Repository($conf['repository']['path'], $conf['repository']['iscontainer'])); +BSRegister::Register('repos', $repos = new Repository($conf['repository']['path'], $conf['repository']['iscontainer'], $conf['repository']['include'])); // ################################################################### // path manager diff --git a/includes/repository.php b/includes/repository.php index 51f78fe..a6bb37d 100644 --- a/includes/repository.php +++ b/includes/repository.php @@ -40,13 +40,7 @@ class Repository * @var array */ private $repositories = array(); - - /** - * Root path to the repository - * @var string - */ - private $path; - + /** * Whether or not the path is a container * @var bool @@ -57,39 +51,50 @@ class Repository /** * Constructor: prepare for repository * - * @param string Path to repository or container + * @param mixed Path to repository or container * @param bool Whether the path is a container + * @param array Array of paths to include (only applicable with containers) */ - function __construct($path, $iscontainer) + function __construct($path, $iscontainer, $include) { global $viewsvn; - $this->path = BSFunctions::FetchSourcePath($path); - $this->container = (bool)$iscontainer; - - if ($this->container) + if (is_array($include) AND sizeof($include) > 0 AND $iscontainer) + { + $this->container = (sizeof($include) > 1); + foreach ($include AS $repos) + { + $this->repositories[$repos] = BSFunctions::FetchSourcePath(BSFunctions::FetchSourcePath($path) . $repos); + } + } + else { - if ($dir = @opendir($this->path)) + $path = BSFunctions::FetchSourcePath($path); + $this->container = (bool)$iscontainer; + if ($this->container) { - while (($file = readdir($dir)) !== false) + if ($dir = @opendir($path)) { - if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db')) + while (($file = readdir($dir)) !== false) { - $this->repositories[] = $file; + if (is_dir($path . $file) AND $file{0} != '.' AND is_dir($path . $file . '/' . 'db')) + { + $this->repositories[$file] = $path . $file; + } } + closedir($dir); } - closedir($dir); } - } - else - { - if (is_dir($this->path . 'db')) + else { - $this->repositories[] = $this->path; + if (is_dir($path . 'db')) + { + $this->repositories[basename($path)] = $path; + } } } - sort($this->repositories); + ksort($this->repositories); if (sizeof($this->repositories) < 1) { @@ -105,7 +110,7 @@ class Repository */ public function fetchList() { - return $this->repositories; + return array_keys($this->repositories); } // ################################################################### @@ -120,19 +125,12 @@ class Repository { global $viewsvn; - if (!in_array($repository, $this->repositories)) + if (!isset($this->repositories[$repository])) { $viewsvn->trigger->error(_('Invalid repository name specified')); } - if ($this->container) - { - return 'file://' . $this->path . $repository; - } - else - { - return 'file://' . $this->path; - } + return 'file://' . $this->repositories[$repository]; } // ################################################################### -- 2.22.5