diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2019-09-21 14:38:22 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-11-08 09:27:54 +0100 |
commit | ffe74210d64550d5e731d1179567b4fdc746fd7a (patch) | |
tree | cb4c109743dd733c9a4a092e7577c52700e55b80 /org.eclipse.jgit/src | |
parent | b7810be174a48668179bfca3e215c6b4b333ad08 (diff) | |
download | jgit-ffe74210d64550d5e731d1179567b4fdc746fd7a.tar.gz jgit-ffe74210d64550d5e731d1179567b4fdc746fd7a.zip |
SystemReader: extract updating config and its parents if outdated
Change-Id: Ia77f442e47c5670c2d6d279ba862044016aabd86
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java | 14 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java | 47 |
2 files changed, 47 insertions, 14 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 16db717032..d26b7fd17d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -129,9 +129,21 @@ public class Config { } /** + * Retrieves this config's base config. + * + * @return the base configuration of this config. + * + * @since 5.5.2 + */ + public Config getBaseConfig() { + return baseConfig; + } + + /** * Check if a given string is the "missing" value. * - * @param value string to be checked. + * @param value + * string to be checked. * @return true if the given string is the "missing" value. * @since 5.4 */ 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 b80ffb51b5..a2253bc118 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -288,20 +288,16 @@ public abstract class SystemReader { * @since 5.1.9 */ public StoredConfig getUserConfig() - throws IOException, ConfigInvalidException { + throws ConfigInvalidException, IOException { 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(); } + // on the very first call this will check a second time if the system + // config is outdated + updateAll(c); return c; } @@ -319,21 +315,46 @@ public abstract class SystemReader { * @since 5.1.9 */ public StoredConfig getSystemConfig() - throws IOException, ConfigInvalidException { + throws ConfigInvalidException, IOException { 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(); - } + updateAll(c); return c; } /** + * Update config and its parents if they seem modified + * + * @param config + * configuration to reload if outdated + * @throws ConfigInvalidException + * if configuration is invalid + * @throws IOException + * if something went wrong when reading files + */ + private void updateAll(Config config) + throws ConfigInvalidException, IOException { + if (config == null) { + return; + } + updateAll(config.getBaseConfig()); + if (config instanceof FileBasedConfig) { + FileBasedConfig cfg = (FileBasedConfig) config; + if (!cfg.getFile().exists()) { + return; + } + if (cfg.isOutdated()) { + LOG.debug("loading config {}", cfg); //$NON-NLS-1$ + cfg.load(); + } + } + } + + /** * Get the current system time * * @return the current system time |