1) Use the overloaded method scanwith AbstractTreeIteratorand call it as follows if there is no parent:
df.scan(new EmptyTreeIterator(),
new CanonicalTreeParser(null, rw.getObjectReader(), commit.getTree());
The case without a parent element is only for the initial commit, in which case the "before" diff value is empty.
2) git diff, :
df.format(diff);
diff , . , , DiffFormatter . DiffFormatter ByteArrayOutputStream, reset . :
ByteArrayOutputStream out = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(out);
for (DiffEntry diff : diffs) {
df.format(diff);
String diffText = out.toString("UTF-8");
out.reset();
}
, Git , toString(). . , toByteArray().
. , RevWalk DiffFormat release().
source
share