private TreeFormatter createTreeFormatter( Map<SubtreeConfig, RevCommit> parentCommits, String commitMessage) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { TreeWalk treeWalk = new TreeWalk(repository); try { treeWalk.setRecursive(false); addTrees(parentCommits, treeWalk); TreeFormatter treeFormatter = new TreeFormatter(); while (treeWalk.next()) { AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage); if (iterator == null) { throw new IllegalStateException( "Tree walker did not return a single tree (should not happen): " + treeWalk.getPathString()); } treeFormatter.append( iterator.getEntryPathBuffer(), 0, iterator.getEntryPathLength(), iterator.getEntryFileMode(), iterator.getEntryObjectId()); } return treeFormatter; } finally { treeWalk.release(); } }