Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-09-21 12:38:22 +0000
committerMatthias Sohn2019-11-08 08:27:54 +0000
commitffe74210d64550d5e731d1179567b4fdc746fd7a (patch)
treecb4c109743dd733c9a4a092e7577c52700e55b80
parentb7810be174a48668179bfca3e215c6b4b333ad08 (diff)
downloadjgit-ffe74210d64550d5e731d1179567b4fdc746fd7a.tar.gz
jgit-ffe74210d64550d5e731d1179567b4fdc746fd7a.tar.xz
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>
-rw-r--r--org.eclipse.jgit/.settings/.api_filters8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java47
3 files changed, 55 insertions, 14 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index f50ea9a6d5..5717512964 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -29,6 +29,14 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/jgit/lib/Config.java" type="org.eclipse.jgit.lib.Config">
+ <filter id="1142947843">
+ <message_arguments>
+ <message_argument value="5.5.2"/>
+ <message_argument value="getBaseConfig()"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants">
<filter id="1142947843">
<message_arguments>
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

Back to the top