public static void main(String args[]) throws IOException, GitAPIException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { final String[] list = new File(".").list(); if(list == null) { throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath()); } for(String file : list) { if(new File(file).isDirectory()) { continue; } System.out.println("Blaming " + file); final BlameResult result = new Git(repo).blame().setFilePath(file) .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call(); final RawText rawText = result.getResultContents(); for (int i = 0; i < rawText.size(); i++) { final PersonIdent sourceAuthor = result.getSourceAuthor(i); final RevCommit sourceCommit = result.getSourceCommit(i); System.out.println(sourceAuthor.getName() + (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") + ": " + rawText.getString(i)); } } } } }
public static void main(String args[]) throws IOException, GitAPIException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { final String[] list = new File(".").list(); if(list == null) { throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath()); } for(String file : list) { if(new File(file).isDirectory()) { continue; } System.out.println("Blaming " + file); final BlameResult result = new Git(repo).blame().setFilePath(file) .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call(); final RawText rawText = result.getResultContents(); for (int i = 0; i < rawText.size(); i++) { final PersonIdent sourceAuthor = result.getSourceAuthor(i); final RevCommit sourceCommit = result.getSourceCommit(i); System.out.println(sourceAuthor.getName() + (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") + ": " + rawText.getString(i)); } } } } }
BlameResult blameResult = git.blame().setFilePath( ... ).call(); int size = blameResult.getResultContents().size(); for( int i = 0; i < size; i++ ) { System.out.println( blameResult.getSourceAuthor( i ) ); }
private int findLine(int b, String regex) { String re = regex.substring(1, regex.length() - 1); if (!re.startsWith("^")) //$NON-NLS-1$ re = ".*" + re; //$NON-NLS-1$ if (!re.endsWith("$")) //$NON-NLS-1$ re = re + ".*"; //$NON-NLS-1$ Pattern p = Pattern.compile(re); RawText text = blame.getResultContents(); for (int line = b; line < text.size(); line++) { if (p.matcher(text.getString(line)).matches()) return line; } return b; }
end = blame.getResultContents().size(); else if (endStr.startsWith("/")) //$NON-NLS-1$ end = findLine(begin, endStr);
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); } }
for (int line : request) { int lineIndex = line - 1; // first line is index 0 if (lineIndex < blame.getResultContents().size()) { PersonIdent who = blame.getSourceAuthor(lineIndex); if (who == null) {
end = blame.getResultContents().size(); if (rangeString != null) parseLineRangeOption(); outw.format(lineFmt, valueOf(line + 1)); outw.flush(); blame.getResultContents().writeLine(outs, line); outs.flush(); outw.print('\n');
return; for (int i = 0; i < blameResult.getResultContents().size(); i++) { if (blameResult.getSourceAuthor(i) == null || blameResult.getSourceCommit(i) == null) { LOG.debug("Unable to blame file {}. No blame info at line {}. Is file committed? [Author: {} Source commit: {}]", inputFile.relativePath(), i + 1,
int total = gitBlameResult.getResultContents().size(); int i = 0; String content = gitBlameResult.getResultContents().getString(i);
int lineCount = result.getResultContents().size(); BlameRevision previous = null; for (int i = 0; i < lineCount; i++) {
int total = gitBlameResult.getResultContents().size(); int i = 0; String content = gitBlameResult.getResultContents().getString(i);
for (int line : request) { int lineIndex = line - 1; // first line is index 0 if (lineIndex < blame.getResultContents().size()) { PersonIdent who = blame.getSourceAuthor(lineIndex); if (who == null) {