Mercurial > public > src > phphgadmin
diff admin/application/libraries/hg_confparser.php @ 1:2d2757428cc6
Repository directory can detect if a repo is enabled, disabled, or missing. Can also parse hgweb.config with a compatibility fix (convert / to ---- as defined in config)
author | joshjcarrier |
---|---|
date | Wed, 28 Apr 2010 00:24:40 -0700 |
parents | 9124b60de5a6 |
children | 492f28533a05 |
line wrap: on
line diff
--- a/admin/application/libraries/hg_confparser.php Tue Apr 27 22:42:57 2010 -0700 +++ b/admin/application/libraries/hg_confparser.php Wed Apr 28 00:24:40 2010 -0700 @@ -38,7 +38,7 @@ } } - /* + /** * Returns a list of available repositories. * Will show up if: detected in repo directory * Will have status "enabled" if: detected in hgweb.config @@ -48,12 +48,34 @@ function lsdir() { $realdir = $this->__realdirscan(); + $hgwebdir_compat = $this->__hgwebconfscan(); - //$dirs = array_diff($realdir, $hgwebdir); - return $realdir;//array('projectx'=>'path', 'projecty'=>'path2'); + // FIXME test no directory cases + $allrepo = array_merge($realdir, array_keys($hgwebdir_compat['collections'])); + + $hgrepos = array(); + foreach($allrepo as $repo) + { + $hgrepos[$repo]['name'] = $repo; + + if(isset($realdir[$repo]) && isset($hgwebdir_compat['collections'][$repo])) + { + $hgrepos[$repo]['status'] = 1; + } + else if(isset($realdir[$repo]) && !isset($hgwebdir_compat['collections'][$repo])) + { + $hgrepos[$repo]['status'] = 0; + } + else if(!isset($realdir[$repo]) && isset($hgwebdir_compat['collections'][$repo])) + { + $hgrepos[$repo]['status'] = 2; + } + } + + return $hgrepos; } - /* + /** * Performs a real directory scan where the projects are suppose to reside. * * @return the array containing 0 or more valid directories @@ -71,13 +93,59 @@ // checks if we detected a folder if(is_dir($this->_repositories_dir . $file)) { - $verifiedrealdir[] = $file; + $verifiedrealdir[$file] = $file; } } return $verifiedrealdir; } + /** + * Scans Mercurial's webconf.config configuration file, detecting + * registered repositories. + */ + function __hgwebconfscan() + { + $hgwebconf_compat = $this->__hgwebconf_compat_load(); + + return $hgwebconf_compat; + } + + /** + * Compatibility layer for Mercurial PHP config files, + * which contain forward slashes '\' as key values. + * + * @return contents of a php_ini array compatible representation + */ + function __hgwebconf_compat_load() + { + // load the PHP to file + $hgwebconf = $this->_hgwebconf_path; + $fh = fopen($hgwebconf, 'r'); + $hgwebconf_str = fread($fh, filesize($hgwebconf)); + fclose($fh); + + // replace all occurances of the forward slash '/' + $hgwebconf_str = str_replace('/', $this->_compatability_delimiter, $hgwebconf_str); + + // load the new compat ini + $hgwebconf = parse_ini_string($hgwebconf_str, TRUE); + + // orients the collections properly + $hgwebconf['collections'] = array_flip($hgwebconf['collections']); + + return $hgwebconf; + } + + /** + * Takes a PHP-compatable php_ini array and converts it back into the original file. + * + */ + function __hgwebconf_compat_persist($hgwebconf_compat_string) + { + + } + function getProjectParams() { return array('ui'=>array('config1'=>'value'));