From: Thomas Wolf Date: Tue, 26 Sep 2017 21:54:45 +0000 (+0200) Subject: HttpConfig: load user config before reading values from it X-Git-Tag: v4.9.0.201710071750-r~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6dab29f4b578bc164acb77083440e4087ed94ff4;p=jgit.git HttpConfig: load user config before reading values from it Same problem as in commit c227268: openUserConfig() just creates the FileBasedConfig object, but doesn't read the file yet. An explicit load() is needed. As HttpConfig is read-only this omission did not cause any bad effects, but it simply ignored values from the user config. Most uses of HttpConfig go through the two-argument constructor, though, where HttpConfig is given an already loaded repo config. Change-Id: Ibe7c562c17d6ef37de8b661ab7f6fa0246db01a2 Signed-off-by: Thomas Wolf --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java index 1435e99195..db59a54a27 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java @@ -44,13 +44,16 @@ package org.eclipse.jgit.transport; +import java.io.IOException; import java.net.URISyntaxException; import java.text.MessageFormat; import java.util.Set; import java.util.function.Supplier; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.StringUtils; import org.eclipse.jgit.util.SystemReader; @@ -142,13 +145,13 @@ public class HttpConfig { } } - private final int postBuffer; + private int postBuffer; - private final boolean sslVerify; + private boolean sslVerify; - private final HttpRedirectMode followRedirects; + private HttpRedirectMode followRedirects; - private final int maxRedirects; + private int maxRedirects; /** * @return the value of the "http.postBuffer" setting @@ -187,6 +190,32 @@ public class HttpConfig { * to get the configuration values for */ public HttpConfig(Config config, URIish uri) { + init(config, uri); + } + + /** + * Creates a {@link HttpConfig} that reads values solely from the user + * config. + * + * @param uri + * to get the configuration values for + */ + public HttpConfig(URIish uri) { + FileBasedConfig userConfig = SystemReader.getInstance() + .openUserConfig(null, FS.DETECTED); + try { + userConfig.load(); + } catch (IOException | ConfigInvalidException e) { + // Log it and then work with default values. + LOG.error(MessageFormat.format(JGitText.get().userConfigFileInvalid, + userConfig.getFile().getAbsolutePath(), e)); + init(new Config(), uri); + return; + } + init(userConfig, uri); + } + + private void init(Config config, URIish uri) { // Set defaults from the section first int postBufferSize = config.getInt(HTTP, POST_BUFFER_KEY, 1 * 1024 * 1024); @@ -220,17 +249,6 @@ public class HttpConfig { maxRedirects = redirectLimit; } - /** - * Creates a {@link HttpConfig} that reads values solely from the user - * config. - * - * @param uri - * to get the configuration values for - */ - public HttpConfig(URIish uri) { - this(SystemReader.getInstance().openUserConfig(null, FS.DETECTED), uri); - } - /** * Determines the best match from a set of subsection names (representing * prefix URLs) for the given {@link URIish}.