Skip to content

Commit dbf9547

Browse files
committed
adding waitfor for the current branch process
1 parent 257121d commit dbf9547

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.List;
4242
import java.util.Locale;
4343
import java.util.TreeSet;
44+
import java.util.concurrent.TimeUnit;
4445
import java.util.logging.Level;
4546
import java.util.logging.Logger;
4647
import java.util.regex.Matcher;
@@ -675,15 +676,27 @@ String determineCurrentVersion() throws IOException {
675676
cmd.add("-1");
676677
cmd.add("--pretty=%cd: %h %an %s");
677678
cmd.add("--date=format:%Y-%m-%d %H:%M");
679+
678680
ProcessBuilder pb = new ProcessBuilder(cmd);
679681
pb.directory(directory);
680-
Process process;
681-
process = pb.start();
682+
Process process = pb.start();
682683

683-
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
684-
if ((line = in.readLine()) != null) {
685-
line = line.trim();
684+
try {
685+
process.waitFor(15, TimeUnit.SECONDS);
686+
687+
if (process.exitValue() != 0) {
688+
throw new IOException("Process exited with non zero exit code");
689+
}
690+
691+
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
692+
if ((line = in.readLine()) != null) {
693+
line = line.trim();
694+
}
686695
}
696+
} catch (InterruptedException ex) {
697+
LOGGER.log(Level.FINE, "Unable to determine current version for {} - process timeouted", getDirectoryName());
698+
} catch (IOException ex) {
699+
LOGGER.log(Level.FINE, "Unable to determine current version for {} - bad exit code", getDirectoryName());
687700
}
688701

689702
return line;

0 commit comments

Comments
 (0)