Skip to content

Commit 4ef8870

Browse files
committed
Ensure access to autoRefresh is thread-safe
Change-Id: I7651613c33803daf00882a543dbf0c3f836110fa
1 parent ac5146f commit 4ef8870

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableDatabase.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525
import java.util.Set;
2626
import java.util.TreeSet;
27+
import java.util.concurrent.atomic.AtomicBoolean;
2728
import java.util.concurrent.locks.Lock;
2829
import java.util.concurrent.locks.ReentrantLock;
2930
import java.util.stream.Collectors;
@@ -72,7 +73,7 @@ public class FileReftableDatabase extends RefDatabase {
7273

7374
private final FileReftableStack reftableStack;
7475

75-
private boolean autoRefresh;
76+
private final AtomicBoolean autoRefresh;
7677

7778
FileReftableDatabase(FileRepository repo) throws IOException {
7879
this(repo, new File(new File(repo.getCommonDirectory(), Constants.REFTABLE),
@@ -81,9 +82,9 @@ public class FileReftableDatabase extends RefDatabase {
8182

8283
FileReftableDatabase(FileRepository repo, File refstackName) throws IOException {
8384
this.fileRepository = repo;
84-
this.autoRefresh = repo.getConfig().getBoolean(
85+
this.autoRefresh = new AtomicBoolean(repo.getConfig().getBoolean(
8586
ConfigConstants.CONFIG_REFTABLE_SECTION,
86-
ConfigConstants.CONFIG_KEY_AUTOREFRESH, false);
87+
ConfigConstants.CONFIG_KEY_AUTOREFRESH, false));
8788
this.reftableStack = new FileReftableStack(refstackName,
8889
new File(fileRepository.getCommonDirectory(), Constants.REFTABLE),
8990
() -> fileRepository.fireEvent(new RefsChangedEvent()),
@@ -241,7 +242,7 @@ public Ref peel(Ref ref) throws IOException {
241242
* date.
242243
*/
243244
public void setAutoRefresh(boolean autoRefresh) {
244-
this.autoRefresh = autoRefresh;
245+
this.autoRefresh.set(autoRefresh);
245246
}
246247

247248
/**
@@ -251,11 +252,11 @@ public void setAutoRefresh(boolean autoRefresh) {
251252
* date.
252253
*/
253254
public boolean isAutoRefresh() {
254-
return autoRefresh;
255+
return autoRefresh.get();
255256
}
256257

257258
private void autoRefresh() {
258-
if (autoRefresh) {
259+
if (autoRefresh.get()) {
259260
refresh();
260261
}
261262
}

0 commit comments

Comments
 (0)