Skip to content

Commit 0f39711

Browse files
committed
RCS needs external 'blame' command to work properly
fixes HistoryGuruTest#annotation()
1 parent 58797cf commit 0f39711

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

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

2020
/*
21-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -29,13 +29,15 @@
2929
import java.io.OutputStream;
3030
import java.util.ArrayList;
3131
import java.util.List;
32+
import java.util.function.Supplier;
3233
import java.util.logging.Level;
3334
import java.util.logging.Logger;
3435

3536
import org.opengrok.indexer.configuration.CommandTimeoutType;
3637
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3738
import org.opengrok.indexer.util.Executor;
3839
import org.opengrok.indexer.logger.LoggerFactory;
40+
import org.opengrok.indexer.util.LazilyInstantiate;
3941

4042
/**
4143
* Access to an RCS repository.
@@ -49,20 +51,38 @@ public class RCSRepository extends Repository {
4951
/**
5052
* This property name is used to obtain the command to get annotation for this repository.
5153
*/
52-
private static final String CMD_BLAME_PROPERTY_KEY
53-
= "org.opengrok.indexer.history.RCS.blame";
54+
private static final String CMD_BLAME_PROPERTY_KEY = "org.opengrok.indexer.history.RCS.blame";
5455
/**
5556
* The command to use to get annotation if none was given explicitly.
5657
*/
5758
private static final String CMD_BLAME_FALLBACK = "blame";
5859

60+
/**
61+
* This is a static replacement for 'working' field. Effectively, check if hg is working once in a JVM
62+
* instead of calling it for every MercurialRepository instance.
63+
*/
64+
private static final Supplier<Boolean> BLAME_IS_WORKING = LazilyInstantiate.using(RCSRepository::isBlameWorking);
65+
5966
public RCSRepository() {
60-
working = Boolean.TRUE;
6167
type = "RCS";
6268

6369
ignoredDirs.add("RCS");
6470
}
6571

72+
private static boolean isBlameWorking() {
73+
String repoCommand = getCommand(MercurialRepository.class, CMD_BLAME_PROPERTY_KEY, CMD_BLAME_FALLBACK);
74+
return checkCmd(repoCommand);
75+
}
76+
77+
@Override
78+
public boolean isWorking() {
79+
if (working == null) {
80+
working = BLAME_IS_WORKING.get();
81+
ensureCommand(CMD_BLAME_PROPERTY_KEY, CMD_BLAME_FALLBACK);
82+
}
83+
return working;
84+
}
85+
6686
@Override
6787
boolean fileHasHistory(File file) {
6888
return getRCSFile(file) != null;

0 commit comments

Comments
 (0)