|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | /*
|
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. |
22 | 22 | * Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
|
23 | 23 | */
|
24 | 24 | package org.opengrok.indexer.history;
|
|
28 | 28 | import java.io.OutputStream;
|
29 | 29 | import java.util.ArrayList;
|
30 | 30 | import java.util.List;
|
| 31 | +import java.util.function.Supplier; |
31 | 32 | import java.util.logging.Level;
|
32 | 33 | import java.util.logging.Logger;
|
33 | 34 | import javax.xml.XMLConstants;
|
|
40 | 41 | import org.opengrok.indexer.configuration.RuntimeEnvironment;
|
41 | 42 | import org.opengrok.indexer.logger.LoggerFactory;
|
42 | 43 | import org.opengrok.indexer.util.Executor;
|
| 44 | +import org.opengrok.indexer.util.LazilyInstantiate; |
43 | 45 | import org.w3c.dom.Document;
|
44 | 46 | import org.w3c.dom.Node;
|
45 | 47 | import org.xml.sax.SAXException;
|
@@ -75,6 +77,12 @@ public class SubversionRepository extends Repository {
|
75 | 77 |
|
76 | 78 | protected String reposPath;
|
77 | 79 |
|
| 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 | + |
78 | 86 | public SubversionRepository() {
|
79 | 87 | type = "Subversion";
|
80 | 88 | datePatterns = new String[]{
|
@@ -354,11 +362,16 @@ boolean isRepositoryFor(File file, CommandTimeoutType cmdType) {
|
354 | 362 | return false;
|
355 | 363 | }
|
356 | 364 |
|
| 365 | + private static boolean isSvnWorking() { |
| 366 | + String repoCommand = getCommand(SubversionRepository.class, CMD_PROPERTY_KEY, CMD_FALLBACK); |
| 367 | + return checkCmd(repoCommand, "--help"); |
| 368 | + } |
| 369 | + |
357 | 370 | @Override
|
358 | 371 | public boolean isWorking() {
|
359 | 372 | if (working == null) {
|
| 373 | + working = SVN_IS_WORKING.get(); |
360 | 374 | ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
|
361 |
| - working = checkCmd(RepoCommand, "--help"); |
362 | 375 | }
|
363 | 376 | return working;
|
364 | 377 | }
|
|
0 commit comments