18
18
*/
19
19
20
20
/*
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.
22
22
* Portions Copyright (c) 2018, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opengrok .indexer .history ;
29
29
import java .io .OutputStream ;
30
30
import java .util .ArrayList ;
31
31
import java .util .List ;
32
+ import java .util .function .Supplier ;
32
33
import java .util .logging .Level ;
33
34
import java .util .logging .Logger ;
34
35
35
36
import org .opengrok .indexer .configuration .CommandTimeoutType ;
36
37
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
37
38
import org .opengrok .indexer .util .Executor ;
38
39
import org .opengrok .indexer .logger .LoggerFactory ;
40
+ import org .opengrok .indexer .util .LazilyInstantiate ;
39
41
40
42
/**
41
43
* Access to an RCS repository.
@@ -49,20 +51,38 @@ public class RCSRepository extends Repository {
49
51
/**
50
52
* This property name is used to obtain the command to get annotation for this repository.
51
53
*/
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" ;
54
55
/**
55
56
* The command to use to get annotation if none was given explicitly.
56
57
*/
57
58
private static final String CMD_BLAME_FALLBACK = "blame" ;
58
59
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
+
59
66
public RCSRepository () {
60
- working = Boolean .TRUE ;
61
67
type = "RCS" ;
62
68
63
69
ignoredDirs .add ("RCS" );
64
70
}
65
71
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
+
66
86
@ Override
67
87
boolean fileHasHistory (File file ) {
68
88
return getRCSFile (file ) != null ;
0 commit comments