public List<BlamedLine> blame(String file, String commitToBeBlamed, boolean priorCommit) { try (Git git = openRepository()) { ObjectId gitCommitToBeBlamed; if (priorCommit) { Iterable<RevCommit> commits = git.log().add(git.getRepository().resolve(commitToBeBlamed)).call(); gitCommitToBeBlamed = commits.iterator().next().getParent(0).getId(); } else { gitCommitToBeBlamed = git.getRepository().resolve(commitToBeBlamed); } BlameResult blameResult = git.blame().setFilePath(file).setStartCommit(gitCommitToBeBlamed).setFollowFileRenames(true).call(); if (blameResult != null) { int rows = blameResult.getResultContents().size(); List<BlamedLine> result = new ArrayList<>(); for (int i = 0; i < rows; i++) { result.add(new BlamedLine(i, blameResult.getResultContents().getString(i), blameResult.getSourceAuthor(i).getName(), blameResult.getSourceCommitter(i).getName(), blameResult.getSourceCommit(i).getId().getName())); } return result; } else { throw new RuntimeException("BlameResult not found."); } } catch (Exception e) { throw new RuntimeException(e); } }
.date(blameResult.getSourceCommitter(i).getWhen()) .revision(blameResult.getSourceCommit(i).getName()) .author(blameResult.getSourceAuthor(i).getEmailAddress()));
blameResult.getSourceCommit( i ).getName(), blameResult.getSourceAuthor( i ).getName(), blameResult.getSourceCommitter( i ).getName() ) );
blameResult.getSourceCommit( i ).getName(), blameResult.getSourceAuthor( i ).getName(), blameResult.getSourceCommitter( i ).getName() ) );