]> khamidou — GitHub mirrors - arcanist.git/commitdiff
[arcanist] add system arc config file
authordschleimer <dschleimer@fb.com>
Mon, 25 Jun 2012 22:14:11 +0000 (15:14 -0700)
committerdschleimer <dschleimer@fb.com>
Mon, 25 Jun 2012 22:14:11 +0000 (15:14 -0700)
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
src/repository/api/ArcanistRepositoryAPI.php
src/workflow/ArcanistBaseWorkflow.php
src/workflow/ArcanistGetConfigWorkflow.php
src/workingcopyidentity/ArcanistWorkingCopyIdentity.php

index 046810779f144e05f905d1241f2ea48c7d5c1ed8..21da391107fa0176dbd98a23958ab90ca71f950c 100644 (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}'.");
index 82abf1b89e2b285f3fc63084b63db96f23658609..25f7459509cd23a6997c23a07e82fc6ec7198c36 100644 (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;
index 4870934bdc669e6a07dfc11fd54e899406b2c779..222d12558ed795948096693500df8f8b4207eaba 100644 (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';
index 3a8892327ceb0b8738ebb0f290b65abc6a255d72..8c90360c4e81d442b88eaf70ea3960f5976da6ca 100644 (file)
@@ -53,6 +53,7 @@ EOTEXT
     $argv = $this->getArgument('argv');
 
     $configs = array(
+      'system' => self::readSystemArcConfig(),
       'global' => self::readGlobalArcConfig(),
       'local' => $this->readLocalArcConfig(),
     );
index e862e169e62d9de859e1de94247b6c671d299dff..3ab892a75953db193cf554cc12536823cd1c50a3 100644 (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;