Class DirCacheTree
DirCache
extension.
A valid cache tree record contains the object id of a tree object and the
total number of DirCacheEntry
instances
(counted recursively) from the DirCache contained within the tree. This
information facilitates faster traversal of the index and quicker generation
of tree objects prior to creating a new commit.
An invalid cache tree record indicates a known subtree whose file entries have changed in ways that cause the tree to no longer have a known object id. Invalid cache tree records must be revalidated prior to use.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Number of valid children inchildren
.private DirCacheTree[]
Child trees, if any, sorted byencodedName
.(package private) byte[]
Name of this tree within its parent.private int
Number ofDirCacheEntry
records that belong to this tree.private ObjectId
Unique SHA-1 of this tree; null if invalid.private static final DirCacheTree[]
private static final byte[]
private DirCacheTree
Tree this tree resides in; null if we are the root.private static final Comparator<DirCacheTree>
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
(package private)
DirCacheTree
(byte[] in, MutableInteger off, DirCacheTree myParent) private
DirCacheTree
(DirCacheTree myParent, byte[] path, int pathOff, int pathLen) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private int
computeSize
(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter ow) (package private) final boolean
contains
(byte[] a, int aOff, int aLen) getChild
(int i) Get the i-th child cache tree.int
Get the number of cached subtrees contained within this tree.int
Get the number of entries this tree spans within the DirCache.Get the tree's name within its parent.Get the tree's ObjectId.Get the tree's path within the repository.private void
insertChild
(int stIdx, DirCacheTree st) boolean
isValid()
Determine if this cache is currently valid.private static int
namecmp
(byte[] a, int aPos, DirCacheTree ct) (package private) final int
(package private) static boolean
peq
(byte[] a, byte[] b, int aLen) private void
removeChild
(int stIdx) private static int
slash
(byte[] a, int aPos) toString()
(package private) void
validate
(DirCacheEntry[] cache, int cCnt, int cIdx, int pathOff) Update (if necessary) this tree's entrySpan.(package private) void
write
(byte[] tmp, OutputStream os) (package private) ObjectId
writeTree
(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter ow) Write (if necessary) this tree to the object store.
-
Field Details
-
NO_NAME
private static final byte[] NO_NAME -
NO_CHILDREN
-
TREE_CMP
-
parent
Tree this tree resides in; null if we are the root. -
encodedName
byte[] encodedNameName of this tree within its parent. -
entrySpan
private int entrySpanNumber ofDirCacheEntry
records that belong to this tree. -
id
Unique SHA-1 of this tree; null if invalid. -
children
Child trees, if any, sorted byencodedName
. -
childCnt
private int childCntNumber of valid children inchildren
.
-
-
Constructor Details
-
DirCacheTree
DirCacheTree() -
DirCacheTree
-
DirCacheTree
DirCacheTree(byte[] in, MutableInteger off, DirCacheTree myParent)
-
-
Method Details
-
write
- Throws:
IOException
-
isValid
public boolean isValid()Determine if this cache is currently valid.A valid cache tree knows how many
DirCacheEntry
instances from the parentDirCache
reside within this tree (recursively enumerated). It also knows the object id of the tree, as the tree should be readily available from the repository's object database.- Returns:
- true if this tree is knows key details about itself; false if the tree needs to be regenerated.
-
getEntrySpan
public int getEntrySpan()Get the number of entries this tree spans within the DirCache.If this tree is not valid (see
isValid()
) this method's return value is always strictly negative (less than 0) but is otherwise an undefined result.- Returns:
- total number of entries (recursively) contained within this tree.
-
getChildCount
public int getChildCount()Get the number of cached subtrees contained within this tree.- Returns:
- number of child trees available through this tree.
-
getChild
Get the i-th child cache tree.- Parameters:
i
- index of the child to obtain.- Returns:
- the child tree.
-
getObjectId
Get the tree's ObjectId.If
isValid()
returns false this method will return null.- Returns:
- ObjectId of this tree or null.
- Since:
- 4.3
-
getNameString
Get the tree's name within its parent.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.
- Returns:
- name of the tree. This does not contain any '/' characters.
-
getPathString
Get the tree's path within the repository.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.
- Returns:
- 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 ("").
-
writeTree
ObjectId writeTree(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter ow) throws UnmergedPathException, IOException Write (if necessary) this tree to the object store.- Parameters:
cache
- the complete cache from DirCache.cIdx
- first position ofcache
that is a member of this tree. The path ofcache[cacheIdx].path
for the range[0,pathOff-1)
matches the complete path of this tree, from the root of the repository.pathOffset
- number of bytes ofcache[cacheIdx].path
that matches this tree's path. The value at array positioncache[cacheIdx].path[pathOff-1]
is always '/' ifpathOff
is > 0.ow
- the writer to use when serializing to the store.- Returns:
- identity of this tree.
- Throws:
UnmergedPathException
- one or more paths contain higher-order stages (stage > 0), which cannot be stored in a tree object.IOException
- an unexpected error occurred writing to the object store.
-
computeSize
private int computeSize(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter ow) throws UnmergedPathException, IOException - Throws:
UnmergedPathException
IOException
-
appendName
-
nameLength
final int nameLength() -
contains
final boolean contains(byte[] a, int aOff, int aLen) -
validate
Update (if necessary) this tree's entrySpan.- Parameters:
cache
- the complete cache from DirCache.cCnt
- number of entries incache
that are valid for iteration.cIdx
- first position ofcache
that is a member of this tree. The path ofcache[cacheIdx].path
for the range[0,pathOff-1)
matches the complete path of this tree, from the root of the repository.pathOff
- number of bytes ofcache[cacheIdx].path
that matches this tree's path. The value at array positioncache[cacheIdx].path[pathOff-1]
is always '/' ifpathOff
is > 0.
-
insertChild
-
removeChild
private void removeChild(int stIdx) -
peq
static boolean peq(byte[] a, byte[] b, int aLen) -
namecmp
-
slash
private static int slash(byte[] a, int aPos) -
toString
-