public static void main(String[] args) throws IOException, GitAPIException { // prepare a new test-repository try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { BlameCommand blamer = new BlameCommand(repository); ObjectId commitID = repository.resolve("HEAD~~"); blamer.setStartCommit(commitID); blamer.setFilePath("README.md"); BlameResult blame = blamer.call(); // read the number of lines from the given revision, this excludes changes from the last two commits due to the "~~" above int lines = countLinesOfFileInCommit(repository, commitID, "README.md"); for (int i = 0; i < lines; i++) { RevCommit commit = blame.getSourceCommit(i); System.out.println("Line: " + i + ": " + commit); } final int currentLines; try (final FileInputStream input = new FileInputStream("README.md")) { currentLines = IOUtils.readLines(input, "UTF-8").size(); } System.out.println("Displayed commits responsible for " + lines + " lines of README.md, current version has " + currentLines + " lines"); } }
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; .revision(blameResult.getSourceCommit(i).getName()) .author(blameResult.getSourceAuthor(i).getEmailAddress()));
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new test-repository try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { BlameCommand blamer = new BlameCommand(repository); ObjectId commitID = repository.resolve("HEAD~~"); blamer.setStartCommit(commitID); blamer.setFilePath("README.md"); BlameResult blame = blamer.call(); // read the number of lines from the given revision, this excludes changes from the last two commits due to the "~~" above int lines = countLinesOfFileInCommit(repository, commitID, "README.md"); for (int i = 0; i < lines; i++) { RevCommit commit = blame.getSourceCommit(i); System.out.println("Line: " + i + ": " + commit); } final int currentLines; try (final FileInputStream input = new FileInputStream("README.md")) { currentLines = IOUtils.readLines(input, "UTF-8").size(); } System.out.println("Displayed commits responsible for " + lines + " lines of README.md, current version has " + currentLines + " lines"); } }
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); } }
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.getSourceCommit( i ).getName(), blameResult.getSourceAuthor( i ).getName(), blameResult.getSourceCommitter( i ).getName() ) );
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.getSourceCommit( i ).getName(), blameResult.getSourceAuthor( i ).getName(), blameResult.getSourceCommitter( i ).getName() ) );
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())); }
int maxSourceLine = 1; for (int line = begin; line < end; line++) { RevCommit c = blame.getSourceCommit(line); if (c != null && !c.has(scanned)) { c.add(scanned); pathWidth = Math.max(pathWidth, path(line).length()); while (line + 1 < end && blame.getSourceCommit(line + 1) == c) line++; maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line)); RevCommit c = blame.getSourceCommit(line); String commit = abbreviate(c); String author = null; outs.flush(); outw.print('\n'); } while (++line < end && blame.getSourceCommit(line) == c);
request.setEmail(line, who.getEmailAddress()); RevCommit commit = blame.getSourceCommit(lineIndex); if (commit == null) { log("No commit ID found for line %d in file %s.%n", lineIndex, fileName);
BlameRevision previous = null; for (int i = 0; i < lineCount; i++) { RevCommit commit = result.getSourceCommit(i); if (commit == null) {
RevCommit commit = gitBlameResult.getSourceCommit(i);
RevCommit commit = gitBlameResult.getSourceCommit(i);
request.setEmail(line, who.getEmailAddress()); RevCommit commit = blame.getSourceCommit(lineIndex); if (commit == null) { log.logError("- no commit ID found for line %d in file %s", lineIndex, fileName);