Skip to content

Commit 2613410

Browse files
authored
Merge pull request #1284 from tulinkry/mercurial-current-version
adding current version info into mercurial repository
2 parents a460fd3 + 0cb5b1b commit 2613410

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

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

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

2020
/*
21-
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.history;
2424

@@ -33,11 +33,11 @@
3333
import java.util.HashMap;
3434
import java.util.List;
3535
import java.util.TreeSet;
36+
import java.util.concurrent.TimeUnit;
3637
import java.util.logging.Level;
3738
import java.util.logging.Logger;
3839
import java.util.regex.Matcher;
3940
import java.util.regex.Pattern;
40-
4141
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
4242
import org.opensolaris.opengrok.logger.LoggerFactory;
4343
import org.opensolaris.opengrok.util.Executor;
@@ -681,4 +681,43 @@ String determineParent() throws IOException {
681681

682682
return executor.getOutputString().trim();
683683
}
684+
685+
@Override
686+
String determineCurrentVersion() throws IOException {
687+
String line = null;
688+
File directory = new File(directoryName);
689+
690+
List<String> cmd = new ArrayList<>();
691+
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
692+
cmd.add(RepoCommand);
693+
cmd.add("log");
694+
cmd.add("-l");
695+
cmd.add("1");
696+
cmd.add("--template");
697+
cmd.add("{date|isodate}: {node|short} {author} {desc|strip}");
698+
699+
ProcessBuilder pb = new ProcessBuilder(cmd);
700+
pb.directory(directory);
701+
Process process = pb.start();
702+
703+
try {
704+
process.waitFor(15, TimeUnit.SECONDS);
705+
706+
if (process.exitValue() != 0) {
707+
throw new IOException("Process exited with non zero exit code");
708+
}
709+
710+
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
711+
if ((line = in.readLine()) != null) {
712+
line = line.trim();
713+
}
714+
}
715+
} catch (InterruptedException ex) {
716+
LOGGER.log(Level.FINE, "Unable to determine current version for {} - process timeouted", getDirectoryName());
717+
} catch (IOException ex) {
718+
LOGGER.log(Level.FINE, "Unable to determine current version for {} - bad exit code", getDirectoryName());
719+
}
720+
721+
return line;
722+
}
684723
}

0 commit comments

Comments
 (0)