List of usage examples for org.eclipse.jgit.diff DiffFormatter format
public void format(AbstractTreeIterator a, AbstractTreeIterator b) throws IOException
From source file:com.google.gerrit.server.mail.NewChangeSender.java
License:Apache License
/** Show patch set as unified difference. */ public String getUnifiedDiff() { PatchList patchList;/*from w ww . j a va2s.co m*/ try { patchList = getPatchList(); if (patchList.getOldId() == null) { // Octopus merges are not well supported for diff output by Gerrit. // Currently these always have a null oldId in the PatchList. return ""; } } catch (PatchListNotAvailableException e) { log.error("Cannot format patch", e); return ""; } TemporaryBuffer.Heap buf = new TemporaryBuffer.Heap(args.settings.maximumDiffSize); DiffFormatter fmt = new DiffFormatter(buf); Repository git; try { git = args.server.openRepository(change.getProject()); } catch (IOException e) { log.error("Cannot open repository to format patch", e); return ""; } try { fmt.setRepository(git); fmt.setDetectRenames(true); fmt.format(patchList.getOldId(), patchList.getNewId()); return RawParseUtils.decode(buf.toByteArray()); } catch (IOException e) { if (JGitText.get().inMemoryBufferLimitExceeded.equals(e.getMessage())) { return ""; } log.error("Cannot format patch", e); return ""; } finally { fmt.release(); git.close(); } }
From source file:com.google.gitiles.DiffServlet.java
License:Open Source License
private void formatHtmlDiff(OutputStream out, Repository repo, RevWalk walk, AbstractTreeIterator oldTree, AbstractTreeIterator newTree, String path) throws IOException { DiffFormatter diff = new HtmlDiffFormatter(renderer, out); try {//from w ww. j a va 2 s. c o m if (!path.equals("")) { diff.setPathFilter(PathFilter.create(path)); } diff.setRepository(repo); diff.setDetectRenames(true); diff.format(oldTree, newTree); } finally { diff.release(); } }
From source file:com.thoughtworks.go.service.ConfigRepository.java
License:Apache License
String findDiffBetweenTwoRevisions(RevCommit laterCommit, RevCommit earlierCommit) {
if (laterCommit == null || earlierCommit == null) {
return null;
}//from www . j a v a 2 s . c om
String output = null;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
DiffFormatter diffFormatter = new DiffFormatter(out);
diffFormatter.setRepository(gitRepo);
diffFormatter.format(earlierCommit.getId(), laterCommit.getId());
output = out.toString();
output = StringUtil.stripTillLastOccurrenceOf(output, "+++ b/cruise-config.xml");
} catch (IOException e) {
throw new RuntimeException("Error occurred during diff computation. Message: " + e.getMessage());
}
return output;
}
From source file:elegit.DiffHelper.java
License:Open Source License
private String getDiffString() throws GitAPIException, IOException { ObjectId head = this.repo.resolve("HEAD"); if (head == null) return ""; // The following code is largely written by Tk421 on StackOverflow // (http://stackoverflow.com/q/23486483) // Thanks! NOTE: comments are mine. ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream(); DiffFormatter formatter = new DiffFormatter(diffOutputStream); formatter.setRepository(this.repo); formatter.setPathFilter(PathFilter.create(this.pathFilter.replaceAll("\\\\", "/"))); AbstractTreeIterator commitTreeIterator = prepareTreeParser(this.repo, head.getName()); FileTreeIterator workTreeIterator = new FileTreeIterator(this.repo); // Scan gets difference between the two iterators. formatter.format(commitTreeIterator, workTreeIterator); return diffOutputStream.toString(); }
From source file:org.nuxeo.lang.ext.LangExtAssistantRoot.java
License:Open Source License
private String getRepoDiff(String languageKey) throws NoWorkTreeException, CorruptObjectException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); String filePath = CLASSES_FOLDER_PATH + "messages_" + languageKey + ".properties"; DiffFormatter df = new DiffFormatter(out); df.setRepository(localRepo);//from w ww. ja va 2 s.c om df.setPathFilter(PathFilterGroup.createFromStrings(filePath)); DirCacheIterator oldTree = new DirCacheIterator(localRepo.readDirCache()); FileTreeIterator newTree = new FileTreeIterator(localRepo); df.format(oldTree, newTree); df.flush(); df.release(); String diff = out.toString("utf-8"); return diff; }