aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-08-15 01:25:28 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-08-18 11:47:26 +0200
commitf383206ace187ec92672b806e18a54e8d398a27d (patch)
tree28403a0987ef5b4dd5af51e4d29944ff07826d61 /org.eclipse.jgit.junit/src
parent7f92a70fb3a5b7e91e5d370098fa65f6c8f35efa (diff)
downloadjgit-f383206ace187ec92672b806e18a54e8d398a27d.tar.gz
jgit-f383206ace187ec92672b806e18a54e8d398a27d.zip
Cache user global and system-wide git configurations
So far the git configuration and the system wide git configuration were always reloaded when jgit accessed these global configuration files to access global configuration options which are not in the context of a single git repository. Cache these configurations in SystemReader and only reload them if their file metadata observed using FileSnapshot indicates a modification. Change-Id: I092fe11a5d95f1c5799273cacfc7a415d0b7786c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java9
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java41
2 files changed, 45 insertions, 5 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
index f8f0c18cba..29579d007f 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
@@ -137,14 +137,15 @@ public abstract class LocalDiskRepositoryTestCase {
// the same one here
FS.getFileStoreAttributes(tmp.toPath().getParent());
- mockSystemReader.userGitConfig = new FileBasedConfig(new File(tmp,
- "usergitconfig"), FS.DETECTED);
+ FileBasedConfig userConfig = new FileBasedConfig(
+ new File(tmp, "usergitconfig"), FS.DETECTED);
// We have to set autoDetach to false for tests, because tests expect to be able
// to clean up by recursively removing the repository, and background GC might be
// in the middle of writing or deleting files, which would disrupt this.
- mockSystemReader.userGitConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION,
+ userConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION,
null, ConfigConstants.CONFIG_KEY_AUTODETACH, false);
- mockSystemReader.userGitConfig.save();
+ userConfig.save();
+ mockSystemReader.setUserGitConfig(userConfig);
ceilTestDirectories(getCeilings());
author = new PersonIdent("J. Author", "jauthor@example.com");
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
index 92b531d191..123fdb305f 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
@@ -60,6 +60,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;
@@ -100,11 +101,37 @@ public class MockSystemReader extends SystemReader {
final Map<String, String> values = new HashMap<>();
- FileBasedConfig userGitConfig;
+ private FileBasedConfig userGitConfig;
FileBasedConfig systemGitConfig;
/**
+ * Set the user-level git config
+ *
+ * @param userGitConfig
+ * set another user-level git config
+ * @return the old user-level git config
+ */
+ public FileBasedConfig setUserGitConfig(FileBasedConfig userGitConfig) {
+ FileBasedConfig old = this.userGitConfig;
+ this.userGitConfig = userGitConfig;
+ return old;
+ }
+
+ /**
+ * Set the system-level git config
+ *
+ * @param systemGitConfig
+ * the new system-level git config
+ * @return the old system-level config
+ */
+ public FileBasedConfig setSystemGitConfig(FileBasedConfig systemGitConfig) {
+ FileBasedConfig old = this.systemGitConfig;
+ this.systemGitConfig = systemGitConfig;
+ return old;
+ }
+
+ /**
* Constructor for <code>MockSystemReader</code>
*/
public MockSystemReader() {
@@ -166,6 +193,18 @@ public class MockSystemReader extends SystemReader {
return systemGitConfig;
}
+ @Override
+ public StoredConfig getUserConfig()
+ throws IOException, ConfigInvalidException {
+ return userGitConfig;
+ }
+
+ @Override
+ public StoredConfig getSystemConfig()
+ throws IOException, ConfigInvalidException {
+ return systemGitConfig;
+ }
+
/** {@inheritDoc} */
@Override
public String getHostname() {