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 <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2017-09-26 23:54:45 +02:00
parent c227268995
commit 6dab29f4b5
1 changed files with 33 additions and 15 deletions

View File

@ -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 boolean matchConfigValue(String s) {
}
}
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 int getMaxRedirects() {
* 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 HttpConfig(Config config, URIish uri) {
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}.