From 82d05fee9f5b7e1cd90a09dee0afc64cbc84dd2c Mon Sep 17 00:00:00 2001 From: dschleimer Date: Mon, 25 Jun 2012 15:14:11 -0700 Subject: [PATCH] [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 --- src/parser/ArcanistBaseCommitParser.php | 3 +++ src/repository/api/ArcanistRepositoryAPI.php | 2 ++ src/workflow/ArcanistBaseWorkflow.php | 23 +++++++++++++++++++ src/workflow/ArcanistGetConfigWorkflow.php | 1 + .../ArcanistWorkingCopyIdentity.php | 11 ++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/parser/ArcanistBaseCommitParser.php b/src/parser/ArcanistBaseCommitParser.php index 04681077..21da3911 100644 --- a/src/parser/ArcanistBaseCommitParser.php +++ b/src/parser/ArcanistBaseCommitParser.php @@ -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}'."); diff --git a/src/repository/api/ArcanistRepositoryAPI.php b/src/repository/api/ArcanistRepositoryAPI.php index 82abf1b8..25f74595 100644 --- a/src/repository/api/ArcanistRepositoryAPI.php +++ b/src/repository/api/ArcanistRepositoryAPI.php @@ -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; diff --git a/src/workflow/ArcanistBaseWorkflow.php b/src/workflow/ArcanistBaseWorkflow.php index 4870934b..222d1255 100644 --- a/src/workflow/ArcanistBaseWorkflow.php +++ b/src/workflow/ArcanistBaseWorkflow.php @@ -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'; diff --git a/src/workflow/ArcanistGetConfigWorkflow.php b/src/workflow/ArcanistGetConfigWorkflow.php index 3a889232..8c90360c 100644 --- a/src/workflow/ArcanistGetConfigWorkflow.php +++ b/src/workflow/ArcanistGetConfigWorkflow.php @@ -53,6 +53,7 @@ EOTEXT $argv = $this->getArgument('argv'); $configs = array( + 'system' => self::readSystemArcConfig(), 'global' => self::readGlobalArcConfig(), 'local' => $this->readLocalArcConfig(), ); diff --git a/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php b/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php index e862e169..3ab892a7 100644 --- a/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php +++ b/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php @@ -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; -- 2.43.0