projectRoot = $root; $this->projectConfig = $config; $this->localConfig = array(); $vc_dirs = array( '.git', '.hg', '.svn', ); $found_meta_dir = false; foreach ($vc_dirs as $dir) { $meta_path = Filesystem::resolvePath( $dir, $this->projectRoot); if (Filesystem::pathExists($meta_path)) { $found_meta_dir = true; $local_path = Filesystem::resolvePath( 'arc/config', $meta_path); if (Filesystem::pathExists($local_path)) { $file = Filesystem::readFile($local_path); if ($file) { $this->localConfig = json_decode($file, true); } } break; } } if (!$found_meta_dir) { // Try for a single higher-level .svn directory as used by svn 1.7+ foreach (Filesystem::walkToRoot($this->projectRoot) as $parent_path) { $local_path = Filesystem::resolvePath( '.svn/arc/config', $parent_path); if (Filesystem::pathExists($local_path)) { $file = Filesystem::readFile($local_path); if ($file) { $this->localConfig = json_decode($file, true); } } } } } public function getProjectID() { return $this->getConfig('project_id'); } public function getProjectRoot() { return $this->projectRoot; } public function getConduitURI() { return $this->getConfig('conduit_uri'); } /* -( Config )------------------------------------------------------------- */ /** * Read a configuration directive from project configuration. This reads ONLY * permanent project configuration (i.e., ".arcconfig"), not other * configuration sources. See @{method:getConfigFromAnySource} to read from * user configuration. * * @param key Key to read. * @param wild Default value if key is not found. * @return wild Value, or default value if not found. * * @task config */ public function getConfig($key, $default = null) { return idx($this->projectConfig, $key, $default); } /** * Read a configuration directive from local configuration. This * reads ONLY the per-working copy configuration, * i.e. .(git|hg|svn)/arc/config, and not other configuration * sources. See @{method:getConfigFromAnySource} to read from any * config source or @{method:getConfig} to read permanent * project-level config. * * @task config */ public function getLocalConfig($key, $default=null) { return idx($this->localConfig, $key, $default); } /** * Read a configuration directive from any available configuration source. * In contrast to @{method:getConfig}, this will look for the directive in * local and user configuration in addition to project configuration. * The precedence is local > project > user * * @param key Key to read. * @param wild Default value if key is not found. * @return wild Value, or default value if not found. * * @task config */ public function getConfigFromAnySource($key, $default = null) { // try local config first $pval = $this->getLocalConfig($key); // then per-project config if ($pval === null) { $pval = $this->getConfig($key); } // Test for older names in the per-project config only, since // they've only been used there static $deprecated_names = array( 'lint.engine' => 'lint_engine', 'unit.engine' => 'unit_engine', ); if ($pval === null && isset($deprecated_names[$key])) { $pval = $this->getConfig($deprecated_names[$key]); } // lastly, try global (i.e. user-level) config if ($pval === null) { $global_config = ArcanistBaseWorkflow::readGlobalArcConfig(); $pval = idx($global_config, $key); } if ($pval === null) { $system_config = ArcanistBaseWorkflow::readSystemArcConfig(); $pval = idx($system_config, $key); } if ($pval === null) { $pval = $default; } return $pval; } }