ObjectId writeTree(final DirCacheEntry[] cache, int cIdx,
final int pathOffset, final ObjectInserter ow)
throws UnmergedPathException, IOException {
if (id == null) {
final int endIdx = cIdx + entrySpan;
final TreeFormatter fmt = new TreeFormatter(computeSize(cache,
cIdx, pathOffset, ow));
int childIdx = 0;
int entryIdx = cIdx;
while (entryIdx < endIdx) {
final DirCacheEntry e = cache[entryIdx];
final byte[] ep = e.path;
if (childIdx < childCnt) {
final DirCacheTree st = children[childIdx];
if (st.contains(ep, pathOffset, ep.length)) {
fmt.append(st.encodedName, TREE, st.id);
entryIdx += st.entrySpan;
childIdx++;
continue;
}
}
fmt.append(ep, pathOffset, ep.length - pathOffset, e
.getFileMode(), e.idBuffer(), e.idOffset());
entryIdx++;
}
id = ow.insert(fmt);