Browse Source

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>
stable-5.5
Thomas Wolf 5 years ago committed by Matthias Sohn
parent
commit
ffe74210d6
  1. 8
      org.eclipse.jgit/.settings/.api_filters
  2. 14
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
  3. 47
      org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java

8
org.eclipse.jgit/.settings/.api_filters

@ -29,6 +29,14 @@
</message_arguments> </message_arguments>
</filter> </filter>
</resource> </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"> <resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants">
<filter id="1142947843"> <filter id="1142947843">
<message_arguments> <message_arguments>

14
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

@ -128,10 +128,22 @@ public class Config {
state = new AtomicReference<>(newState()); state = new AtomicReference<>(newState());
} }
/**
* 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. * 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. * @return true if the given string is the "missing" value.
* @since 5.4 * @since 5.4
*/ */

47
org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java

@ -288,20 +288,16 @@ public abstract class SystemReader {
* @since 5.1.9 * @since 5.1.9
*/ */
public StoredConfig getUserConfig() public StoredConfig getUserConfig()
throws IOException, ConfigInvalidException { throws ConfigInvalidException, IOException {
FileBasedConfig c = userConfig.get(); FileBasedConfig c = userConfig.get();
if (c == null) { if (c == null) {
userConfig.compareAndSet(null, userConfig.compareAndSet(null,
openUserConfig(getSystemConfig(), FS.DETECTED)); openUserConfig(getSystemConfig(), FS.DETECTED));
c = userConfig.get(); 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; return c;
} }
@ -319,20 +315,45 @@ public abstract class SystemReader {
* @since 5.1.9 * @since 5.1.9
*/ */
public StoredConfig getSystemConfig() public StoredConfig getSystemConfig()
throws IOException, ConfigInvalidException { throws ConfigInvalidException, IOException {
FileBasedConfig c = systemConfig.get(); FileBasedConfig c = systemConfig.get();
if (c == null) { if (c == null) {
systemConfig.compareAndSet(null, systemConfig.compareAndSet(null,
openSystemConfig(null, FS.DETECTED)); openSystemConfig(null, FS.DETECTED));
c = systemConfig.get(); c = systemConfig.get();
} }
if (c.isOutdated()) { updateAll(c);
LOG.debug("loading system config {}", systemConfig); //$NON-NLS-1$
c.load();
}
return 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 * Get the current system time
* *

Loading…
Cancel
Save