Skip to content

Commit bc0daf2

Browse files
committed
use LazilyInstantiate
1 parent a92645b commit bc0daf2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/SubversionRepository.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -28,6 +28,7 @@
2828
import java.io.OutputStream;
2929
import java.util.ArrayList;
3030
import java.util.List;
31+
import java.util.function.Supplier;
3132
import java.util.logging.Level;
3233
import java.util.logging.Logger;
3334
import javax.xml.XMLConstants;
@@ -40,6 +41,7 @@
4041
import org.opengrok.indexer.configuration.RuntimeEnvironment;
4142
import org.opengrok.indexer.logger.LoggerFactory;
4243
import org.opengrok.indexer.util.Executor;
44+
import org.opengrok.indexer.util.LazilyInstantiate;
4345
import org.w3c.dom.Document;
4446
import org.w3c.dom.Node;
4547
import org.xml.sax.SAXException;
@@ -75,6 +77,12 @@ public class SubversionRepository extends Repository {
7577

7678
protected String reposPath;
7779

80+
/**
81+
* This is a static replacement for 'working' field. Effectively, check if the svn command is working once in a JVM
82+
* instead of calling it for every {@link SubversionRepository} instance.
83+
*/
84+
private static final Supplier<Boolean> SVN_IS_WORKING = LazilyInstantiate.using(SubversionRepository::isSvnWorking);
85+
7886
public SubversionRepository() {
7987
type = "Subversion";
8088
datePatterns = new String[]{
@@ -354,11 +362,16 @@ boolean isRepositoryFor(File file, CommandTimeoutType cmdType) {
354362
return false;
355363
}
356364

365+
private static boolean isSvnWorking() {
366+
String repoCommand = getCommand(SubversionRepository.class, CMD_PROPERTY_KEY, CMD_FALLBACK);
367+
return checkCmd(repoCommand, "--help");
368+
}
369+
357370
@Override
358371
public boolean isWorking() {
359372
if (working == null) {
373+
working = SVN_IS_WORKING.get();
360374
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
361-
working = checkCmd(RepoCommand, "--help");
362375
}
363376
return working;
364377
}

0 commit comments

Comments
 (0)