use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method annotate.
@Override
public Annotation annotate(File file, String rev) throws IOException {
Annotation a = new Annotation(file.getName());
ArrayList<String> cmd = new ArrayList<>();
String path = file.getAbsolutePath();
cmd.add(RepoCommand);
cmd.add("annotate");
// version & user
cmd.add("-fvu");
if (rev != null) {
cmd.add("-v");
cmd.add(rev.trim());
}
cmd.add(path);
Executor executor = new Executor(cmd, file.getParentFile());
executor.exec();
try (BufferedReader reader = new BufferedReader(executor.getOutputReader())) {
String line;
int lineno = 0;
try {
while ((line = reader.readLine()) != null) {
++lineno;
Matcher matcher = annotationPattern.matcher(line);
if (matcher.find()) {
String version = matcher.group(1);
String author = matcher.group(2);
a.addLine(version, author, true);
} else {
LOGGER.log(Level.SEVERE, "Did not find annotation in line {0}: [{1}]", new Object[] { lineno, line });
}
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not read annotations for " + file, e);
}
}
return a;
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class BazaarHistoryParser method parse.
History parse(File file, String sinceRevision) throws HistoryException {
try {
Executor executor = repository.getHistoryLogExecutor(file, sinceRevision);
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
}
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
// an exception.
if (sinceRevision != null) {
repository.removeAndVerifyOldestChangeset(entries, sinceRevision);
}
return new History(entries);
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class MercurialHistoryParser method parse.
/**
* Parse the history for the specified file or directory. If a changeset is
* specified, only return the history from the changeset right after the
* specified one.
*
* @param file the file or directory to get history for
* @param changeset the changeset right before the first one to fetch, or
* {@code null} if all changesets should be fetched
* @return history for the specified file or directory
* @throws HistoryException if an error happens when parsing the history
*/
History parse(File file, String changeset) throws HistoryException {
isDir = file.isDirectory();
try {
Executor executor = repository.getHistoryLogExecutor(file, changeset);
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
}
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
// an exception.
if (changeset != null) {
repository.removeAndVerifyOldestChangeset(entries, changeset);
}
return new History(entries, renamedFiles);
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class MercurialRepository method getHistoryLogExecutor.
/**
* Get an executor to be used for retrieving the history log for the named
* file or directory.
*
* @param file The file or directory to retrieve history for
* @param sinceRevision the oldest changeset to return from the executor, or
* {@code null} if all changesets should be returned.
* For files this does not apply and full history is returned.
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(File file, String sinceRevision) throws HistoryException, IOException {
String abs = file.getCanonicalPath();
String filename = "";
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (abs.length() > directoryName.length()) {
filename = abs.substring(directoryName.length() + 1);
}
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
if (file.isDirectory()) {
// on that branch and also follow any changesets from the parent branch.
if (sinceRevision != null) {
cmd.add("-r");
String[] parts = sinceRevision.split(":");
if (parts.length == 2) {
cmd.add("reverse(" + parts[0] + "::'" + getBranch() + "')");
} else {
throw new HistoryException("Don't know how to parse changeset identifier: " + sinceRevision);
}
} else {
cmd.add("-r");
cmd.add("reverse(0::'" + getBranch() + "')");
}
} else {
// For plain files we would like to follow the complete history
// (this is necessary for getting the original name in given revision
// when handling renamed files)
// It is not needed to filter on a branch as 'hg log' will follow
// the active branch.
// Due to behavior of recent Mercurial versions, it is not possible
// to filter the changesets of a file based on revision.
// For files this does not matter since if getHistory() is called
// for a file, the file has to be renamed so we want its complete history.
cmd.add("--follow");
cmd.add(filename);
}
cmd.add("--template");
if (file.isDirectory()) {
cmd.add(env.isHandleHistoryOfRenamedFiles() ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE);
} else {
cmd.add(FILE_TEMPLATE);
}
return new Executor(cmd, new File(directoryName), sinceRevision != null);
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class GitRepository method getHistoryLogExecutor.
/**
* Get an executor to be used for retrieving the history log for the named
* file.
*
* @param file The file to retrieve history for
* @param sinceRevision the oldest changeset to return from the executor, or
* {@code null} if all changesets should be returned
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(final File file, String sinceRevision) throws IOException {
String abs = file.getCanonicalPath();
String filename = "";
if (abs.length() > directoryName.length()) {
filename = abs.substring(directoryName.length() + 1);
}
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
cmd.add("--abbrev-commit");
cmd.add(ABBREV_LOG);
cmd.add("--name-only");
cmd.add("--pretty=fuller");
cmd.add("--date=rfc");
if (file.isFile() && RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
cmd.add("--follow");
}
if (sinceRevision != null) {
cmd.add(sinceRevision + "..");
}
if (filename.length() > 0) {
cmd.add("--");
cmd.add(filename);
}
return new Executor(cmd, new File(getDirectoryName()), sinceRevision != null);
}
Aggregations