mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-18 09:48:38 +01:00
Add hook for runtime config settings.
Summary: This adds a hook to allow external parties to provide config settings at runtime. The hook is technically for when a RepositoryAPI is created, but that moment can be used to set new config settings using the new setRuntimeConfig() api. For example you could have a external hook that looks for keys like 'git:foo.bar' or 'hg:foo.bar' and writes the value of 'foo.bar' based on whether the repo is a git or a hg repo. Test Plan: Created a hook that looks for hg/git prefix versions of config keys. Set hg:arc.feature.start.default to be "master" and set arc.feature.start.default to be "trunk". Ran arc feature in the hg repo. It made a bookmark on master. Ran arc feature in the git repo. It made a branch on trunk. Did it again, but with git:arc.feature... set instead. Reviewers: epriestley Reviewed By: epriestley CC: nh, wez, aran, Korvin Differential Revision: https://secure.phabricator.com/D5357
This commit is contained in:
parent
b7a2766130
commit
3f2c6b629f
1 changed files with 24 additions and 2 deletions
|
@ -12,6 +12,7 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
|
|
||||||
protected $localConfig;
|
protected $localConfig;
|
||||||
protected $projectConfig;
|
protected $projectConfig;
|
||||||
|
protected $runtimeConfig;
|
||||||
protected $projectRoot;
|
protected $projectRoot;
|
||||||
|
|
||||||
public static function newDummyWorkingCopy() {
|
public static function newDummyWorkingCopy() {
|
||||||
|
@ -87,6 +88,7 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
$this->projectRoot = $root;
|
$this->projectRoot = $root;
|
||||||
$this->projectConfig = $config;
|
$this->projectConfig = $config;
|
||||||
$this->localConfig = array();
|
$this->localConfig = array();
|
||||||
|
$this->runtimeConfig = array();
|
||||||
|
|
||||||
$vc_dirs = array(
|
$vc_dirs = array(
|
||||||
'.git',
|
'.git',
|
||||||
|
@ -214,8 +216,13 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
public function getConfigFromAnySource($key, $default = null) {
|
public function getConfigFromAnySource($key, $default = null) {
|
||||||
$settings = new ArcanistSettings();
|
$settings = new ArcanistSettings();
|
||||||
|
|
||||||
// try local config first
|
// try runtime config first
|
||||||
|
$pval = idx($this->runtimeConfig, $key);
|
||||||
|
|
||||||
|
// try local config
|
||||||
|
if ($pval === null) {
|
||||||
$pval = $this->getLocalConfig($key);
|
$pval = $this->getLocalConfig($key);
|
||||||
|
}
|
||||||
|
|
||||||
// then per-project config
|
// then per-project config
|
||||||
if ($pval === null) {
|
if ($pval === null) {
|
||||||
|
@ -244,4 +251,19 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a runtime config value that takes precedence over any static
|
||||||
|
* config values.
|
||||||
|
*
|
||||||
|
* @param key Key to set.
|
||||||
|
* @param value The value of the key.
|
||||||
|
*
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function setRuntimeConfig($key, $value) {
|
||||||
|
$this->runtimeConfig[$key] = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue