final DirCacheTree p = tree.getChild(nextSubtreePos - 1); if (p.contains(cep, pathOffset, cep.length)) { nextSubtreePos--; currentSubtree = p; if (nextSubtreePos != tree.getChildCount()) { final DirCacheTree s = tree.getChild(nextSubtreePos); if (s.contains(cep, pathOffset, cep.length)) { nextSubtreePos++; if (s.isValid()) s.getObjectId().copyRawTo(subtreeId, 0); mode = FileMode.TREE.getBits(); path = cep; pathLen = pathOffset + s.nameLength(); return;
DirCacheIterator(DirCacheIterator p, DirCacheTree dct) { super(p, p.path, p.pathLen + 1); cache = p.cache; tree = dct; treeStart = p.ptr; treeEnd = treeStart + tree.getEntrySpan(); subtreeId = p.subtreeId; ptr = p.ptr; parseEntry(); }
while (cIdx < cCnt) { final byte[] currPath = cache[cIdx].path; if (pathOff > 0 && !peq(firstPath, currPath, pathOff)) { final int cc = namecmp(currPath, pathOff, st); if (cc > 0) { removeChild(stIdx); continue; final int p = slash(currPath, pathOff); if (p < 0) { st = new DirCacheTree(this, currPath, pathOff, p - pathOff); insertChild(stIdx, st); st.validate(cache, cCnt, cIdx, pathOff + st.nameLength() + 1); cIdx += st.entrySpan; entrySpan += st.entrySpan; removeChild(childCnt - 1);
/** * Obtain (or build) the current cache tree structure. * <p> * This method can optionally recreate the cache tree, without flushing the * tree objects themselves to disk. * * @param build * if true and the cache tree is not present in the index it will * be generated and returned to the caller. * @return the cache tree; null if there is no current cache tree available * and <code>build</code> was false. */ public DirCacheTree getCacheTree(boolean build) { if (build) { if (tree == null) tree = new DirCacheTree(); tree.validate(sortedEntries, entryCnt, 0, 0); } return tree; }
private void appendName(StringBuilder r) { if (parent != null) { parent.appendName(r); r.append(getNameString()); r.append('/'); } else if (nameLength() > 0) { r.append(getNameString()); r.append('/'); } }
private void show(final DirCacheTree tree) throws IOException { outw.println(MessageFormat.format(CLIText.get().cacheTreePathInfo, tree.getPathString(), valueOf(tree.getEntrySpan()), valueOf(tree.getChildCount()))); for (int i = 0; i < tree.getChildCount(); i++) show(tree.getChild(i)); } }
private int computeSize(final DirCacheEntry[] cache, int cIdx, final int pathOffset, final ObjectInserter ow) throws UnmergedPathException, IOException { final int endIdx = cIdx + entrySpan; int childIdx = 0; int entryIdx = cIdx; int size = 0; while (entryIdx < endIdx) { final DirCacheEntry e = cache[entryIdx]; if (e.getStage() != 0) throw new UnmergedPathException(e); final byte[] ep = e.path; if (childIdx < childCnt) { final DirCacheTree st = children[childIdx]; if (st.contains(ep, pathOffset, ep.length)) { final int stOffset = pathOffset + st.nameLength() + 1; st.writeTree(cache, entryIdx, stOffset, ow); size += entrySize(TREE, st.nameLength()); entryIdx += st.entrySpan; childIdx++; continue; } } size += entrySize(e.getFileMode(), ep.length - pathOffset); entryIdx++; } return size; }
if (id == null) { final int endIdx = cIdx + entrySpan; final TreeFormatter fmt = new TreeFormatter(computeSize(cache, cIdx, pathOffset, ow)); int childIdx = 0; 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;
children = new DirCacheTree[subcnt]; for (int i = 0; i < subcnt; i++) { children[i] = new DirCacheTree(in, off, this);
/** {@inheritDoc} */ @Override public String toString() { return getNameString(); } }
/** * Get the tree's path within the repository. * <p> * This method is not very efficient and is primarily meant for debugging * and final output generation. Applications should try to avoid calling it, * and if invoked do so only once per interesting entry, where the name is * absolutely required for correct function. * * @return path of the tree, relative to the repository root. If this is not * the root tree the path ends with '/'. The root tree's path string * is the empty string (""). */ public String getPathString() { final StringBuilder r = new StringBuilder(); appendName(r); return r.toString(); }
private void show(final DirCacheTree tree) throws IOException { outw.println(MessageFormat.format(CLIText.get().cacheTreePathInfo, tree.getPathString(), valueOf(tree.getEntrySpan()), valueOf(tree.getChildCount()))); for (int i = 0; i < tree.getChildCount(); i++) show(tree.getChild(i)); } }
private void appendName(final StringBuilder r) { if (parent != null) { parent.appendName(r); r.append(getNameString()); r.append('/'); } else if (nameLength() > 0) { r.append(getNameString()); r.append('/'); } }
private int computeSize(final DirCacheEntry[] cache, int cIdx, final int pathOffset, final ObjectInserter ow) throws UnmergedPathException, IOException { final int endIdx = cIdx + entrySpan; int childIdx = 0; int entryIdx = cIdx; int size = 0; while (entryIdx < endIdx) { final DirCacheEntry e = cache[entryIdx]; if (e.getStage() != 0) throw new UnmergedPathException(e); final byte[] ep = e.path; if (childIdx < childCnt) { final DirCacheTree st = children[childIdx]; if (st.contains(ep, pathOffset, ep.length)) { final int stOffset = pathOffset + st.nameLength() + 1; st.writeTree(cache, entryIdx, stOffset, ow); size += entrySize(TREE, st.nameLength()); entryIdx += st.entrySpan; childIdx++; continue; } } size += entrySize(e.getFileMode(), ep.length - pathOffset); entryIdx++; } return size; }
/** * Obtain (or build) the current cache tree structure. * <p> * This method can optionally recreate the cache tree, without flushing the * tree objects themselves to disk. * * @param build * if true and the cache tree is not present in the index it will * be generated and returned to the caller. * @return the cache tree; null if there is no current cache tree available * and <code>build</code> was false. */ public DirCacheTree getCacheTree(final boolean build) { if (build) { if (tree == null) tree = new DirCacheTree(); tree.validate(sortedEntries, entryCnt, 0, 0); } return tree; }
if (id == null) { final int endIdx = cIdx + entrySpan; final TreeFormatter fmt = new TreeFormatter(computeSize(cache, cIdx, pathOffset, ow)); int childIdx = 0; 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;
IO.readFully(in, raw, 0, raw.length); md.update(raw, 0, raw.length); tree = new DirCacheTree(raw, new MutableInteger(), null); break;
/** {@inheritDoc} */ @Override public String toString() { return getNameString(); } }
/** * Get the tree's path within the repository. * <p> * This method is not very efficient and is primarily meant for debugging * and final output generation. Applications should try to avoid calling it, * and if invoked do so only once per interesting entry, where the name is * absolutely required for correct function. * * @return path of the tree, relative to the repository root. If this is not * the root tree the path ends with '/'. The root tree's path string * is the empty string (""). */ public String getPathString() { final StringBuilder r = new StringBuilder(); appendName(r); return r.toString(); }
while (cIdx < cCnt) { final byte[] currPath = cache[cIdx].path; if (pathOff > 0 && !peq(firstPath, currPath, pathOff)) { final int cc = namecmp(currPath, pathOff, st); if (cc > 0) { removeChild(stIdx); continue; final int p = slash(currPath, pathOff); if (p < 0) { st = new DirCacheTree(this, currPath, pathOff, p - pathOff); insertChild(stIdx, st); st.validate(cache, cCnt, cIdx, pathOff + st.nameLength() + 1); cIdx += st.entrySpan; entrySpan += st.entrySpan; removeChild(childCnt - 1);