/** * Get the text for a single line. * * @param i * index of the line to extract. Note this is 0-based, so line * number 1 is actually index 0. * @return the text for the line, without a trailing LF. */ public String getString(int i) { return getString(i, i + 1, true); }
private boolean isNoNewlineAtEndOfFile(FileHeader fh) { HunkHeader lastHunk = fh.getHunks().get(fh.getHunks().size() - 1); RawText lhrt = new RawText(lastHunk.getBuffer()); return lhrt.getString(lhrt.size() - 1).equals( "\\ No newline at end of file"); //$NON-NLS-1$ } }
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)); } } } } }
/** * Get the text for a single line. * * @param i * index of the line to extract. Note this is 0-based, so line * number 1 is actually index 0. * @return the text for the line, without a trailing LF. */ public String getString(int i) { return getString(i, i + 1, true); }
/** * Get the text for a single line. * * @param i * index of the line to extract. Note this is 0-based, so line * number 1 is actually index 0. * @return the text for the line, without a trailing LF. */ public String getString(int i) { return getString(i, i + 1, true); }
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; }
private static boolean isNoNewlineAtEndOfFile(FileHeader fh) { HunkHeader lastHunk = fh.getHunks().get(fh.getHunks().size() - 1); RawText lhrt = new RawText(lastHunk.getBuffer()); return lhrt.getString(lhrt.size() - 1).equals( "\\ No newline at end of file"); //$NON-NLS-1$ } }
private boolean isNoNewlineAtEndOfFile(FileHeader fh) { HunkHeader lastHunk = fh.getHunks().get(fh.getHunks().size() - 1); RawText lhrt = new RawText(lastHunk.getBuffer()); return lhrt.getString(lhrt.size() - 1).equals( "\\ No newline at end of file"); //$NON-NLS-1$ } }
private boolean isNoNewlineAtEndOfFile(FileHeader fh) { HunkHeader lastHunk = fh.getHunks().get(fh.getHunks().size() - 1); RawText lhrt = new RawText(lastHunk.getBuffer()); return lhrt.getString(lhrt.size() - 1).equals( "\\ No newline at end of file"); //$NON-NLS-1$ } }
/** Populates the value for {@link #next} to be returned. */ private void populateNext() { if (next == null) { nextEdit(); if (currentEdit != null) { if (baseLineNo < currentEdit.getEndA()) { next = new JgitDifference(CheckstyleTextParser.BASE_REPORT_INDEX, baseLineNo, baseFileRaw.getString(baseLineNo)); baseLineNo++; } else if (patchLineNo < currentEdit.getEndB()) { next = new JgitDifference(CheckstyleTextParser.PATCH_REPORT_INDEX, patchLineNo, patchFileRaw.getString(patchLineNo)); patchLineNo++; } } } }
List<String> oldLines = new ArrayList<String>(rt.size()); for (int i = 0; i < rt.size(); i++) oldLines.add(rt.getString(i)); List<String> newLines = new ArrayList<String>(oldLines); for (HunkHeader hh : fh.getHunks()) { List<String> hunkLines = new ArrayList<String>(hrt.size()); for (int i = 0; i < hrt.size(); i++) hunkLines.add(hrt.getString(i)); int pos = 0; for (int j = 1; j < hunkLines.size(); j++) {
List<String> oldLines = new ArrayList<String>(rt.size()); for (int i = 0; i < rt.size(); i++) oldLines.add(rt.getString(i)); List<String> newLines = new ArrayList<String>(oldLines); for (HunkHeader hh : fh.getHunks()) { hunkLines.add(hrt.getString(i)); int pos = 0; for (int j = 1; j < hunkLines.size(); j++) {
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); } }
String content = gitBlameResult.getResultContents().getString(i);
for (int i = 0; i < rawText.size(); i++) { outw.print(" "); //$NON-NLS-1$ outw.println(rawText.getString(i));
String content = gitBlameResult.getResultContents().getString(i);