if (revision != null) {
cmd.add(revision);
}
cmd.add(file.getName());
Executor exec = new Executor(cmd, file.getParentFile());
int status = exec.exec();
// File might have changed its location
if (status != 0) {
cmd.clear();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(this.cmd);
cmd.add(BLAME);
cmd.add("-c"); // to get correctly formed changeset IDs
cmd.add(ABBREV_BLAME);
cmd.add("-C");
cmd.add(file.getName());
exec = new Executor(cmd, file.getParentFile());
status = exec.exec();
if (status != 0) {
OpenGrokLogger.getLogger().log(Level.SEVERE,
"Failed to get blame list");
}
try (BufferedReader in = new BufferedReader(exec.getOutputReader())) {
String pattern = "^\\W*" + revision + " (.+?) .*$";
Pattern commitPattern = Pattern.compile(pattern);
String line = "";
Matcher matcher = commitPattern.matcher(line);
while ((line = in.readLine()) != null) {
matcher.reset(line);
if (matcher.find()) {
String filepath = matcher.group(1);
cmd.clear();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(this.cmd);
cmd.add(BLAME);
cmd.add("-c"); // to get correctly formed changeset IDs
cmd.add(ABBREV_BLAME);
if (revision != null) {
cmd.add(revision);
}
cmd.add("--");
cmd.add(filepath);
File directory = new File(directoryName);
exec = new Executor(cmd, directory);
status = exec.exec();
if (status != 0) {
OpenGrokLogger.getLogger().log(Level.SEVERE,
"Failed to get blame details for modified file path");
}
break;
}
}
}
}
if (status != 0) {
OpenGrokLogger.getLogger().log(Level.WARNING,
"Failed to get annotations for: \"{0}\" Exit code: {1}",
new Object[]{file.getAbsolutePath(), String.valueOf(status)});
}
return parseAnnotation(
newLogReader(exec.getOutputStream()), file.getName());
}