diff options
author | Jonathan Nieder <jrn@google.com> | 2019-08-29 18:16:29 -0700 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2019-08-29 18:16:29 -0700 |
commit | 47a95d1aed3a2e696bfa346b9e395d4b4337dbad (patch) | |
tree | 5aacda2f959b1710d783a63047d7d36c65a5c882 /org.eclipse.jgit | |
parent | f30382b1915723c526e50d7c9669c45a57c8ca86 (diff) | |
parent | 60283a58a79578a41ba31d2f57ac2ef7cf2e1521 (diff) | |
download | jgit-47a95d1aed3a2e696bfa346b9e395d4b4337dbad.tar.gz jgit-47a95d1aed3a2e696bfa346b9e395d4b4337dbad.zip |
Merge branch 'stable-5.2' into stable-5.3
* stable-5.2:
Return a new instance from openSystemConfig and openUserConfig
Change-Id: I6491549ab13aad2a4c3f8444a090a94a378eccdb
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/.settings/.api_filters | 12 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java | 87 |
2 files changed, 39 insertions, 60 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters index 1279cf5597..33630a812b 100644 --- a/org.eclipse.jgit/.settings/.api_filters +++ b/org.eclipse.jgit/.settings/.api_filters @@ -219,18 +219,6 @@ </filter> </resource> <resource path="src/org/eclipse/jgit/util/SystemReader.java" type="org.eclipse.jgit.util.SystemReader"> - <filter id="336695337"> - <message_arguments> - <message_argument value="org.eclipse.jgit.util.SystemReader"/> - <message_argument value="getSystemConfig()"/> - </message_arguments> - </filter> - <filter id="336695337"> - <message_arguments> - <message_argument value="org.eclipse.jgit.util.SystemReader"/> - <message_argument value="getUserConfig()"/> - </message_arguments> - </filter> <filter id="1142947843"> <message_arguments> <message_argument value="5.1.9"/> diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index f99aa80e50..cccac662c4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -98,10 +98,6 @@ public abstract class SystemReader { private static class Default extends SystemReader { private volatile String hostname; - private AtomicReference<FileBasedConfig> systemConfig = new AtomicReference<>(); - - private volatile AtomicReference<FileBasedConfig> userConfig = new AtomicReference<>(); - @Override public String getenv(String variable) { return System.getenv(variable); @@ -114,17 +110,8 @@ public abstract class SystemReader { @Override public FileBasedConfig openSystemConfig(Config parent, FS fs) { - FileBasedConfig c = systemConfig.get(); - if (c == null) { - systemConfig.compareAndSet(null, - createSystemConfig(parent, fs)); - c = systemConfig.get(); - } - return c; - } - - protected FileBasedConfig createSystemConfig(Config parent, FS fs) { - if (StringUtils.isEmptyOrNull(getenv(Constants.GIT_CONFIG_NOSYSTEM_KEY))) { + if (StringUtils + .isEmptyOrNull(getenv(Constants.GIT_CONFIG_NOSYSTEM_KEY))) { File configFile = fs.getGitSystemConfig(); if (configFile != null) { return new FileBasedConfig(parent, configFile, fs); @@ -146,35 +133,8 @@ public abstract class SystemReader { @Override public FileBasedConfig openUserConfig(Config parent, FS fs) { - FileBasedConfig c = userConfig.get(); - if (c == null) { - userConfig.compareAndSet(null, new FileBasedConfig(parent, - new File(fs.userHome(), ".gitconfig"), fs)); //$NON-NLS-1$ - c = userConfig.get(); - } - return c; - } - - @Override - public StoredConfig getSystemConfig() - throws IOException, ConfigInvalidException { - FileBasedConfig c = openSystemConfig(null, FS.DETECTED); - if (c.isOutdated()) { - LOG.debug("loading system config {}", systemConfig); //$NON-NLS-1$ - c.load(); - } - return c; - } - - @Override - public StoredConfig getUserConfig() - throws IOException, ConfigInvalidException { - FileBasedConfig c = openUserConfig(getSystemConfig(), FS.DETECTED); - if (c.isOutdated()) { - LOG.debug("loading user config {}", userConfig); //$NON-NLS-1$ - c.load(); - } - return c; + return new FileBasedConfig(parent, new File(fs.userHome(), ".gitconfig"), //$NON-NLS-1$ + fs); } @Override @@ -234,6 +194,10 @@ public abstract class SystemReader { private ObjectChecker platformChecker; + private AtomicReference<FileBasedConfig> systemConfig = new AtomicReference<>(); + + private AtomicReference<FileBasedConfig> userConfig = new AtomicReference<>(); + private void init() { // Creating ObjectChecker must be deferred. Unit tests change // behavior of is{Windows,MacOS} in constructor of subclass. @@ -323,8 +287,23 @@ public abstract class SystemReader { * if something went wrong when reading files * @since 5.1.9 */ - public abstract StoredConfig getUserConfig() - throws IOException, ConfigInvalidException; + public StoredConfig getUserConfig() + throws IOException, ConfigInvalidException { + FileBasedConfig c = userConfig.get(); + if (c == null) { + userConfig.compareAndSet(null, + openUserConfig(getSystemConfig(), FS.DETECTED)); + c = userConfig.get(); + } else { + // Ensure the parent is up to date + getSystemConfig(); + } + if (c.isOutdated()) { + LOG.debug("loading user config {}", userConfig); //$NON-NLS-1$ + c.load(); + } + return c; + } /** * Get the gitconfig configuration found in the system-wide "etc" directory. @@ -339,8 +318,20 @@ public abstract class SystemReader { * if something went wrong when reading files * @since 5.1.9 */ - public abstract StoredConfig getSystemConfig() - throws IOException, ConfigInvalidException; + public StoredConfig getSystemConfig() + throws IOException, ConfigInvalidException { + FileBasedConfig c = systemConfig.get(); + if (c == null) { + systemConfig.compareAndSet(null, + openSystemConfig(null, FS.DETECTED)); + c = systemConfig.get(); + } + if (c.isOutdated()) { + LOG.debug("loading system config {}", systemConfig); //$NON-NLS-1$ + c.load(); + } + return c; + } /** * Get the current system time |