You can get the tree id for HEAD and hash by calling:
ObjectId head = repository.resolve("HEAD^{tree}");
and for version id:
ObjectId old = repository.resolve(oldHash + "^{tree}");
Once you have tree identifiers, you can create tree iterators and get diff:
ObjectReader reader = repository.newObjectReader(); CanonicalTreeParser oldTreeIter = new CanonicalTreeParser(); oldTreeIter.reset(reader, oldId); CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); newTreeIter.reset(reader, headId); List<DiffEntry> diffs= git.diff() .setNewTree(newTreeIter) .setOldTree(oldTreeIter) .call();
Kevin sawicki
source share