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 String author(int line) { PersonIdent author = blame.getSourceAuthor(line); if (author == null) return ""; //$NON-NLS-1$ String name = showAuthorEmail ? author.getEmailAddress() : author .getName(); return name != null ? name : ""; //$NON-NLS-1$ }
private String date(int line) { if (blame.getSourceCommit(line) == null) return ""; //$NON-NLS-1$ PersonIdent author = blame.getSourceAuthor(line); if (author == null) return ""; //$NON-NLS-1$ dateFmt.setTimeZone(author.getTimeZone()); if (!showRawTimestamp) return dateFmt.format(author.getWhen()); return String.format("%d %s", //$NON-NLS-1$ valueOf(author.getWhen().getTime() / 1000L), dateFmt.format(author.getWhen())); }
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, blameResult.getSourceAuthor(i), blameResult.getSourceCommit(i)); return; .date(blameResult.getSourceCommitter(i).getWhen()) .revision(blameResult.getSourceCommit(i).getName()) .author(blameResult.getSourceAuthor(i).getEmailAddress()));
while ( ( i = blameResult.computeNext() ) != -1 ) lines.add( new BlameLine( blameResult.getSourceAuthor( i ).getWhen(), blameResult.getSourceCommit( i ).getName(), blameResult.getSourceAuthor( i ).getName(), blameResult.getSourceCommitter( i ).getName() ) );
while ( ( i = blameResult.computeNext() ) != -1 ) lines.add( new BlameLine( blameResult.getSourceAuthor( i ).getWhen(), blameResult.getSourceCommit( i ).getName(), blameResult.getSourceAuthor( i ).getName(), blameResult.getSourceCommitter( i ).getName() ) );
int lineIndex = line - 1; // first line is index 0 if (lineIndex < blame.getResultContents().size()) { PersonIdent who = blame.getSourceAuthor(lineIndex); if (who == null) { log("No author information found for line %d in file %s.%n", lineIndex, fileName);
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); } }
PersonIdent author = gitBlameResult.getSourceAuthor(i); BlameLine blameLine = new BlameLine();
PersonIdent author = gitBlameResult.getSourceAuthor(i); BlameLine blameLine = new BlameLine();
int lineIndex = line - 1; // first line is index 0 if (lineIndex < blame.getResultContents().size()) { PersonIdent who = blame.getSourceAuthor(lineIndex); if (who == null) { log.logError("- no author information found for line %d in file %s", lineIndex,