It's a followup question of jgit - git diff based on file extension.
I am trying to add the formatted diff to List<String>
but If I try to use same DiffFormatter
as below then previous entries getting appended to the next one.
List<String> changes = new LinkedList<>();
try (OutputStream outputStream = new ByteArrayOutputStream();
DiffFormatter diffFormatter = new DiffFormatter(outputStream)) {
diffFormatter.setRepository(git1.getRepository());
TreeFilter treeFilter = PathSuffixFilter.create(".txt");
diffFormatter.setPathFilter(treeFilter);
List<DiffEntry> entries = diffFormatter.scan(newTree, oldTree);
for (DiffEntry diffEntry : entries) {
diffFormatter.format(diffEntry);
changes.add(outputStream.toString());
diffFormatter.flush();
}
}
Therefore I forced to create a DIffFormatter
for every diff entry.
Is there a better way to create List<String> from List<DiffEntry>
without creating a new DiffFormatter
every time?