Skip to content

Commit b238bfb

Browse files
author
Vladimir Kotal
authored
various repository methods should use interactive timeout (#2108)
fixes #2094
1 parent 3dae0b7 commit b238bfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2026
-1107
lines changed

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public final class Configuration {
204204
private final Map<String, String> cmds; // repository type -> command
205205
private int tabSize;
206206
private int commandTimeout; // in seconds
207+
private int interactiveCommandTimeout; // in seconds
207208
private boolean scopesEnabled;
208209
private boolean projectsEnabled;
209210
private boolean foldingEnabled;
@@ -348,6 +349,24 @@ public void setCommandTimeout(int commandTimeout) throws IllegalArgumentExceptio
348349
this.commandTimeout = commandTimeout;
349350
}
350351

352+
public int getInteractiveCommandTimeout() {
353+
return interactiveCommandTimeout;
354+
}
355+
356+
/**
357+
* Set the interactive command timeout to a new value.
358+
*
359+
* @param commandTimeout the new value
360+
* @throws IllegalArgumentException when the timeout is negative
361+
*/
362+
public void setInteractiveCommandTimeout(int commandTimeout) throws IllegalArgumentException {
363+
if (commandTimeout < 0) {
364+
throw new IllegalArgumentException(
365+
String.format(NEGATIVE_NUMBER_ERROR, "interactiveCommandTimeout", commandTimeout));
366+
}
367+
this.interactiveCommandTimeout = commandTimeout;
368+
}
369+
351370
public String getStatisticsFilePath() {
352371
return statisticsFilePath;
353372
}
@@ -397,6 +416,7 @@ public Configuration() {
397416
setBugPattern("\\b([12456789][0-9]{6})\\b");
398417
setCachePages(5);
399418
setCommandTimeout(600); // 10 minutes
419+
setInteractiveCommandTimeout(30);
400420
setCompressXref(true);
401421
setContextLimit((short)10);
402422
//contextSurround is default(short)

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ public void setCommandTimeout(int timeout) {
311311
threadConfig.get().setCommandTimeout(timeout);
312312
}
313313

314+
public int getInteractiveCommandTimeout() {
315+
return threadConfig.get().getInteractiveCommandTimeout();
316+
}
317+
318+
public void setInteractiveCommandTimeout(int timeout) {
319+
threadConfig.get().setInteractiveCommandTimeout(timeout);
320+
}
321+
314322
public Statistics getStatistics() {
315323
return statistics;
316324
}
@@ -1372,6 +1380,16 @@ public void readConfiguration(File file) throws IOException {
13721380
setConfiguration(Configuration.read(file));
13731381
}
13741382

1383+
/**
1384+
* Read configuration from a file and put it into effect.
1385+
* @param file the file to read
1386+
* @param interactive true if run in interactive mode
1387+
* @throws IOException
1388+
*/
1389+
public void readConfiguration(File file, boolean interactive) throws IOException {
1390+
setConfiguration(Configuration.read(file), null, interactive);
1391+
}
1392+
13751393
/**
13761394
* Write the current configuration to a file
13771395
*
@@ -1493,10 +1511,10 @@ public void populateGroups(Set<Group> groups, Set<Project> projects) {
14931511
* @param configuration what configuration to use
14941512
*/
14951513
public void setConfiguration(Configuration configuration) {
1496-
setConfiguration(configuration, null);
1514+
setConfiguration(configuration, null, false);
14971515
}
14981516

1499-
public void setConfiguration(Configuration configuration, List<String> subFileList) {
1517+
public void setConfiguration(Configuration configuration, List<String> subFileList, boolean interactive) {
15001518
this.configuration = configuration;
15011519
// HistoryGuru constructor uses environment properties so register()
15021520
// needs to be called first.
@@ -1516,10 +1534,10 @@ public void setConfiguration(Configuration configuration, List<String> subFileLi
15161534
// Set the working repositories in HistoryGuru.
15171535
if (subFileList != null) {
15181536
histGuru.invalidateRepositories(
1519-
configuration.getRepositories(), subFileList);
1537+
configuration.getRepositories(), subFileList, interactive);
15201538
} else {
1521-
histGuru.invalidateRepositories(
1522-
configuration.getRepositories());
1539+
histGuru.invalidateRepositories(configuration.getRepositories(),
1540+
interactive);
15231541
}
15241542
// The invalidation of repositories above might have excluded some
15251543
// repositories in HistoryGuru so the configuration needs to reflect that.

src/org/opensolaris/opengrok/configuration/messages/ProjectMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
226226
List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
227227
if (riList != null) {
228228
for (RepositoryInfo ri : riList) {
229-
Repository repo = getRepository(ri);
229+
Repository repo = getRepository(ri, false);
230230

231231
if (repo != null && repo.getCurrentVersion() != null &&
232232
repo.getCurrentVersion().length() > 0) {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.history;
24+
25+
import java.io.BufferedReader;
26+
import java.io.IOException;
27+
import java.io.InputStream;
28+
import java.io.InputStreamReader;
29+
import java.util.logging.Level;
30+
import java.util.logging.Logger;
31+
import java.util.regex.Matcher;
32+
import java.util.regex.Pattern;
33+
import org.opensolaris.opengrok.logger.LoggerFactory;
34+
import org.opensolaris.opengrok.util.Executor;
35+
36+
/**
37+
* handles parsing the output of the {@code accurev annotate} command
38+
* into an annotation object.
39+
*/
40+
public class AccuRevAnnotationParser implements Executor.StreamHandler {
41+
42+
private static final Logger LOGGER = LoggerFactory.getLogger(AccuRevAnnotationParser.class);
43+
44+
private static final Pattern ANNOTATION_PATTERN
45+
= Pattern.compile("^\\s+(\\d+.\\d+)\\s+(\\w+)"); // version, user
46+
47+
/**
48+
* Store annotation created by processStream.
49+
*/
50+
private final Annotation annotation;
51+
52+
/**
53+
* @param fileName the name of the file being annotated
54+
*/
55+
public AccuRevAnnotationParser(String fileName) {
56+
annotation = new Annotation(fileName);
57+
}
58+
59+
/**
60+
* Returns the annotation that has been created.
61+
*
62+
* @return annotation an annotation object
63+
*/
64+
public Annotation getAnnotation() {
65+
return annotation;
66+
}
67+
68+
@Override
69+
public void processStream(InputStream input) throws IOException {
70+
try (BufferedReader reader
71+
= new BufferedReader(new InputStreamReader(input))) {
72+
String line;
73+
int lineno = 0;
74+
try {
75+
while ((line = reader.readLine()) != null) {
76+
++lineno;
77+
Matcher matcher = ANNOTATION_PATTERN.matcher(line);
78+
79+
if (matcher.find()) {
80+
// On Windows machines version shows up as
81+
// <number>\<number>. To get search annotation
82+
// to work properly, need to flip '\' to '/'.
83+
// This is a noop on Unix boxes.
84+
String version = matcher.group(1).replace('\\', '/');
85+
String author = matcher.group(2);
86+
annotation.addLine(version, author, true);
87+
} else {
88+
LOGGER.log(Level.SEVERE,
89+
"Did not find annotation in line {0}: [{1}]",
90+
new Object[]{lineno, line});
91+
}
92+
}
93+
} catch (IOException e) {
94+
LOGGER.log(Level.SEVERE,
95+
"Could not read annotations for " + annotation.getFilename(), e);
96+
}
97+
}
98+
}
99+
}

src/org/opensolaris/opengrok/history/AccuRevRepository.java

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public class AccuRevRepository extends Repository {
7979
* The command to use to access the repository if none was given explicitly
8080
*/
8181
public static final String CMD_FALLBACK = "accurev";
82-
private static final Pattern annotationPattern
83-
= Pattern.compile("^\\s+(\\d+.\\d+)\\s+(\\w+)"); // version, user
84-
private static final Pattern depotPattern
82+
83+
private static final Pattern DEPOT_PATTERN
8584
= Pattern.compile("^Depot:\\s+(\\w+)");
86-
private static final Pattern parentPattern
85+
private static final Pattern PARENT_PATTERN
8786
= Pattern.compile("^Basis:\\s+(\\w+)");
88-
private static final Pattern workspaceRootPattern
87+
private static final Pattern WORKSPACE_ROOT_PATTERN
8988
= Pattern.compile("Top:\\s+(.+)$");
89+
9090
private static final RuntimeEnvironment env = RuntimeEnvironment.getInstance();
9191

9292
private String depotName = null;
@@ -111,8 +111,6 @@ public AccuRevRepository() {
111111
@Override
112112
public Annotation annotate(File file, String rev) throws IOException {
113113

114-
Annotation a = new Annotation(file.getName());
115-
116114
ArrayList<String> cmd = new ArrayList<>();
117115

118116
// Do not use absolute paths because symbolic links will cause havoc.
@@ -129,38 +127,12 @@ public Annotation annotate(File file, String rev) throws IOException {
129127

130128
cmd.add(path);
131129

132-
Executor executor = new Executor(cmd, file.getParentFile());
133-
executor.exec();
134-
try (BufferedReader reader
135-
= new BufferedReader(executor.getOutputReader())) {
136-
String line;
137-
int lineno = 0;
138-
try {
139-
while ((line = reader.readLine()) != null) {
140-
++lineno;
141-
Matcher matcher = annotationPattern.matcher(line);
142-
143-
if (matcher.find()) {
144-
// On Windows machines version shows up as
145-
// <number>\<number>. To get search annotation
146-
// to work properly, need to flip '\' to '/'.
147-
// This is a noop on Unix boxes.
148-
String version = matcher.group(1).replace('\\', '/');
149-
String author = matcher.group(2);
150-
a.addLine(version, author, true);
151-
} else {
152-
LOGGER.log(Level.SEVERE,
153-
"Did not find annotation in line {0}: [{1}]",
154-
new Object[]{lineno, line});
155-
}
156-
}
157-
} catch (IOException e) {
158-
LOGGER.log(Level.SEVERE,
159-
"Could not read annotations for " + file, e);
160-
}
161-
}
162-
163-
return a;
130+
Executor executor = new Executor(cmd, file.getParentFile(),
131+
RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
132+
AccuRevAnnotationParser parser = new AccuRevAnnotationParser(file.getName());
133+
executor.exec(true, parser);
134+
135+
return parser.getAnnotation();
164136
}
165137

166138
/**
@@ -299,7 +271,7 @@ public boolean fileHasAnnotation(File file) {
299271
* below 'Server time' will be missing when current working directory
300272
* is not within a known AccuRev workspace/repository.
301273
*/
302-
private boolean getAccuRevInfo( File wsPath ) {
274+
private boolean getAccuRevInfo(File wsPath, boolean interactive) {
303275

304276
ArrayList<String> cmd = new ArrayList<>();
305277
boolean status = false;
@@ -320,7 +292,8 @@ private boolean getAccuRevInfo( File wsPath ) {
320292
cmd.add(RepoCommand);
321293
cmd.add("info");
322294

323-
Executor executor = new Executor(cmd, realWsPath.toFile());
295+
Executor executor = new Executor(cmd, realWsPath.toFile(), interactive ?
296+
env.getInteractiveCommandTimeout() : env.getCommandTimeout());
324297
executor.exec();
325298

326299
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
@@ -334,22 +307,22 @@ private boolean getAccuRevInfo( File wsPath ) {
334307
}
335308

336309
if (line.startsWith("Depot")) {
337-
Matcher depotMatch = depotPattern.matcher(line);
310+
Matcher depotMatch = DEPOT_PATTERN.matcher(line);
338311
if (depotMatch.find()) {
339312
depotName = depotMatch.group(1);
340313
status = true;
341314
}
342315
}
343316

344317
else if (line.startsWith("Basis")) {
345-
Matcher parentMatch = parentPattern.matcher(line);
318+
Matcher parentMatch = PARENT_PATTERN.matcher(line);
346319
if (parentMatch.find()) {
347320
parent = parentMatch.group(1);
348321
}
349322
}
350323

351324
else if (line.startsWith("Top")) {
352-
Matcher workspaceRoot = workspaceRootPattern.matcher(line);
325+
Matcher workspaceRoot = WORKSPACE_ROOT_PATTERN.matcher(line);
353326
if (workspaceRoot.find()) {
354327
wsRoot = workspaceRoot.group(1);
355328
// Normally, the source root path and the workspace root
@@ -417,13 +390,13 @@ else if (line.startsWith("Top")) {
417390
* @param wsPath The presumed path to an AccuRev workspace directory.
418391
* @return true if the given path is in the depot, false otherwise
419392
*/
420-
private boolean isInAccuRevDepot(File wsPath) {
393+
private boolean isInAccuRevDepot(File wsPath, boolean interactive) {
421394

422395
// Once depot name is determined, always assume inside depot.
423396
boolean status = (depotName != null);
424397

425398
if (! status && isWorking()) {
426-
status = getAccuRevInfo( wsPath );
399+
status = getAccuRevInfo(wsPath, interactive);
427400
}
428401

429402
return status;
@@ -474,10 +447,10 @@ public String getDepotRelativePath(File file) {
474447
}
475448

476449
@Override
477-
boolean isRepositoryFor(File sourceHome) {
450+
boolean isRepositoryFor(File sourceHome, boolean interactive) {
478451

479452
if (sourceHome.isDirectory()) {
480-
return isInAccuRevDepot(sourceHome);
453+
return isInAccuRevDepot(sourceHome, interactive);
481454
}
482455

483456
return false;
@@ -505,13 +478,18 @@ History getHistory(File file) throws HistoryException {
505478
}
506479

507480
@Override
508-
String determineParent() throws IOException {
509-
getAccuRevInfo(new File(getDirectoryName()));
481+
String determineParent(boolean interactive) throws IOException {
482+
getAccuRevInfo(new File(getDirectoryName()), interactive);
510483
return parent;
511484
}
512485

513486
@Override
514-
String determineBranch() {
487+
String determineBranch(boolean interactive) {
488+
return null;
489+
}
490+
491+
@Override
492+
String determineCurrentVersion(boolean interactive) throws IOException {
515493
return null;
516494
}
517495
}

src/org/opensolaris/opengrok/history/Annotation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public class Annotation {
4949

5050
private static final Logger LOGGER = LoggerFactory.getLogger(Annotation.class);
5151

52-
private final List<Line> lines = new ArrayList<Line>();
53-
private final Map<String, String> desc = new HashMap<String, String>();
54-
private final Map<String, Integer> fileVersions = new HashMap<String, Integer>(); //maps revision to file version
52+
private final List<Line> lines = new ArrayList<>();
53+
private final Map<String, String> desc = new HashMap<>();
54+
private final Map<String, Integer> fileVersions = new HashMap<>(); // maps revision to file version
5555
private int widestRevision;
5656
private int widestAuthor;
5757
private final String filename;

0 commit comments

Comments
 (0)