summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-08-23 16:00:38 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-08-23 16:00:38 +0200
commitd999d12ad02e142cb4464fab3722b9a72e7ae0ee (patch)
treec8f8c10dc897f174ba12d10a55a6c4eef83f63c5
parent7ac3a63e7fe16503c3b0e3c45b9d32333ef12a82 (diff)
parent418722df34ca007362e23be60ef57dbe6f1d1b7a (diff)
downloadjgit-d999d12ad02e142cb4464fab3722b9a72e7ae0ee.tar.gz
jgit-d999d12ad02e142cb4464fab3722b9a72e7ae0ee.zip
Merge branch 'stable-5.1' into stable-5.2
* stable-5.1: Prepare 5.1.11-SNAPSHOT builds JGit v5.1.10.201908230655-r Use AtomicReferences to cache user and system level configs Fix copy-paste typo in CloneCommand#cleanup Change-Id: Ie383633de334e65901ed4c6deb2d59cfcce98e16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java47
2 files changed, 24 insertions, 25 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index 73af8ba16d..10a54ee459 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -697,7 +697,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
FileUtils.delete(gitDir, FileUtils.RECURSIVE
| FileUtils.SKIP_MISSING | FileUtils.IGNORE_ERRORS);
} else {
- deleteChildren(directory);
+ deleteChildren(gitDir);
}
}
} catch (IOException e) {
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 d554562a75..310bc83a66 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java
@@ -56,6 +56,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.CorruptObjectException;
@@ -97,9 +98,9 @@ public abstract class SystemReader {
private static class Default extends SystemReader {
private volatile String hostname;
- private volatile FileBasedConfig systemConfig;
+ private AtomicReference<FileBasedConfig> systemConfig = new AtomicReference<>();
- private volatile FileBasedConfig userConfig;
+ private volatile AtomicReference<FileBasedConfig> userConfig = new AtomicReference<>();
@Override
public String getenv(String variable) {
@@ -113,10 +114,13 @@ public abstract class SystemReader {
@Override
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
- if (systemConfig == null) {
- systemConfig = createSystemConfig(parent, fs);
+ FileBasedConfig c = systemConfig.get();
+ if (c == null) {
+ systemConfig.compareAndSet(null,
+ createSystemConfig(parent, fs));
+ c = systemConfig.get();
}
- return systemConfig;
+ return c;
}
protected FileBasedConfig createSystemConfig(Config parent, FS fs) {
@@ -142,40 +146,35 @@ public abstract class SystemReader {
@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
- if (userConfig == null) {
- File home = fs.userHome();
- userConfig = new FileBasedConfig(parent,
- new File(home, ".gitconfig"), fs); //$NON-NLS-1$
+ FileBasedConfig c = userConfig.get();
+ if (c == null) {
+ userConfig.compareAndSet(null, new FileBasedConfig(parent,
+ new File(fs.userHome(), ".gitconfig"), fs)); //$NON-NLS-1$
+ c = userConfig.get();
}
- return userConfig;
+ return c;
}
@Override
public StoredConfig getSystemConfig()
throws IOException, ConfigInvalidException {
- if (systemConfig == null) {
- systemConfig = createSystemConfig(null, FS.DETECTED);
- }
- if (systemConfig.isOutdated()) {
+ FileBasedConfig c = openSystemConfig(null, FS.DETECTED);
+ if (c.isOutdated()) {
LOG.debug("loading system config {}", systemConfig); //$NON-NLS-1$
- systemConfig.load();
+ c.load();
}
- return systemConfig;
+ return c;
}
@Override
public StoredConfig getUserConfig()
throws IOException, ConfigInvalidException {
- if (userConfig == null) {
- userConfig = openUserConfig(getSystemConfig(), FS.DETECTED);
- } else {
- getSystemConfig();
- }
- if (userConfig.isOutdated()) {
+ FileBasedConfig c = openUserConfig(getSystemConfig(), FS.DETECTED);
+ if (c.isOutdated()) {
LOG.debug("loading user config {}", userConfig); //$NON-NLS-1$
- userConfig.load();
+ c.load();
}
- return userConfig;
+ return c;
}
@Override