1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 08:52:39 +01:00

[arcanist] add system arc config file

Summary:
Adds a system arc config file with precedence below the user config
file, both to ArcanistWorkingCopyIdentity::readConfigFromAnySource()
and to base commit resolution.

Test Plan:
[14:48:45 Mon Jun 25 2012] dschleimer@dev4022.snc6 ~/devtools/arcanist
arcanist system_config 21245 $ cat /etc/arcconfig
{
    "base": "literal:foobar"
}
[14:52:31 Mon Jun 25 2012] dschleimer@dev4022.snc6 ~/devtools/arcanist
arcanist system_config 21246 $ ./bin/arc get-config base
(system) base = literal:foobar
(global) base =

[14:52:39 Mon Jun 25 2012] dschleimer@dev4022.snc6 ~/devtools/arcanist
arcanist system_config 21247 $ ./bin/arc which --show-base --base 'arc:system'
foobar

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1233

Differential Revision: https://secure.phabricator.com/D2854
This commit is contained in:
dschleimer 2012-06-25 15:14:11 -07:00
parent e1371493be
commit 82d05fee9f
5 changed files with 39 additions and 1 deletions

View file

@ -58,6 +58,7 @@ final class ArcanistBaseCommitParser {
'local' => '',
'project' => '',
'global' => '',
'system' => '',
);
foreach ($specs as $source => $spec) {
@ -69,6 +70,7 @@ final class ArcanistBaseCommitParser {
'local',
'project',
'global',
'system',
);
while ($this->try) {
@ -143,6 +145,7 @@ final class ArcanistBaseCommitParser {
case 'global':
case 'project':
case 'args':
case 'system':
// Push the other source on top of the list.
array_unshift($this->try, $name);
$this->log("Switching to source '{$name}'.");

View file

@ -409,6 +409,7 @@ abstract class ArcanistRepositoryAPI {
public function resolveBaseCommit() {
$working_copy = $this->getWorkingCopyIdentity();
$global_config = ArcanistBaseWorkflow::readGlobalArcConfig();
$system_config = ArcanistBaseWorkflow::readSystemArcConfig();
$parser = new ArcanistBaseCommitParser($this);
$commit = $parser->resolveBaseCommit(
@ -417,6 +418,7 @@ abstract class ArcanistRepositoryAPI {
'local' => $working_copy->getLocalConfig('base', ''),
'project' => $working_copy->getConfig('base', ''),
'global' => idx($global_config, 'base', ''),
'system' => idx($system_config, 'base', ''),
));
return $commit;

View file

@ -965,6 +965,29 @@ abstract class ArcanistBaseWorkflow {
return $argv;
}
public static function getSystemArcConfigLocation() {
if (phutil_is_windows()) {
// this is a horrible place to put this, but there doesn't seem to be a
// non-horrible place on Windows
return Filesystem::resolvePath(
'Phabricator/Arcanist/config',
getenv('PROGRAMFILES'));
} else {
return '/etc/arcconfig';
}
}
public static function readSystemArcConfig() {
$system_config = array();
$system_config_path = self::getSystemArcConfigLocation();
if (Filesystem::pathExists($system_config_path)) {
$file = Filesystem::readFile($system_config_path);
if ($file) {
$system_config = json_decode($file, true);
}
}
return $system_config;
}
public static function getUserConfigurationFileLocation() {
if (phutil_is_windows()) {
return getenv('APPDATA').'/.arcrc';

View file

@ -53,6 +53,7 @@ EOTEXT
$argv = $this->getArgument('argv');
$configs = array(
'system' => self::readSystemArcConfig(),
'global' => self::readGlobalArcConfig(),
'local' => $this->readLocalArcConfig(),
);

View file

@ -202,7 +202,16 @@ final class ArcanistWorkingCopyIdentity {
// lastly, try global (i.e. user-level) config
if ($pval === null) {
$global_config = ArcanistBaseWorkflow::readGlobalArcConfig();
$pval = idx($global_config, $key, $default);
$pval = idx($global_config, $key);
}
if ($pval === null) {
$system_config = ArcanistBaseWorkflow::readSystemArcConfig();
$pval = idx($system_config, $key);
}
if ($pval === null) {
$pval = $default;
}
return $pval;