public class DirCacheTree
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
private int |
childCnt
Number of valid children in
children . |
private DirCacheTree[] |
children
Child trees, if any, sorted by
encodedName . |
(package private) byte[] |
encodedName
Name of this tree within its parent.
|
private int |
entrySpan
Number of
DirCacheEntry records that belong to this tree. |
private ObjectId |
id
Unique SHA-1 of this tree; null if invalid.
|
private static DirCacheTree[] |
NO_CHILDREN |
private static byte[] |
NO_NAME |
private DirCacheTree |
parent
Tree this tree resides in; null if we are the root.
|
private static java.util.Comparator<DirCacheTree> |
TREE_CMP |
Modifier | Constructor and Description |
---|---|
(package private) |
DirCacheTree() |
(package private) |
DirCacheTree(byte[] in,
MutableInteger off,
DirCacheTree myParent) |
private |
DirCacheTree(DirCacheTree myParent,
byte[] path,
int pathOff,
int pathLen) |
Modifier and Type | Method and Description |
---|---|
private void |
appendName(java.lang.StringBuilder r) |
private int |
computeSize(DirCacheEntry[] cache,
int cIdx,
int pathOffset,
ObjectInserter ow) |
(package private) boolean |
contains(byte[] a,
int aOff,
int aLen) |
DirCacheTree |
getChild(int i)
Get the i-th child cache tree.
|
int |
getChildCount()
Get the number of cached subtrees contained within this tree.
|
int |
getEntrySpan()
Get the number of entries this tree spans within the DirCache.
|
java.lang.String |
getNameString()
Get the tree's name within its parent.
|
ObjectId |
getObjectId()
Get the tree's ObjectId.
|
java.lang.String |
getPathString()
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) int |
nameLength() |
(package private) static boolean |
peq(byte[] a,
byte[] b,
int aLen) |
private void |
removeChild(int stIdx) |
private static int |
slash(byte[] a,
int aPos) |
java.lang.String |
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,
java.io.OutputStream os) |
(package private) ObjectId |
writeTree(DirCacheEntry[] cache,
int cIdx,
int pathOffset,
ObjectInserter ow)
Write (if necessary) this tree to the object store.
|
private static final byte[] NO_NAME
private static final DirCacheTree[] NO_CHILDREN
private static final java.util.Comparator<DirCacheTree> TREE_CMP
private DirCacheTree parent
byte[] encodedName
private int entrySpan
DirCacheEntry
records that belong to this tree.private ObjectId id
private DirCacheTree[] children
encodedName
.private int childCnt
children
.DirCacheTree()
private DirCacheTree(DirCacheTree myParent, byte[] path, int pathOff, int pathLen)
DirCacheTree(byte[] in, MutableInteger off, DirCacheTree myParent)
void write(byte[] tmp, java.io.OutputStream os) throws java.io.IOException
java.io.IOException
public boolean isValid()
A valid cache tree knows how many
DirCacheEntry
instances from the parent
DirCache
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.
public int getEntrySpan()
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.
public int getChildCount()
public DirCacheTree getChild(int i)
i
- index of the child to obtain.public ObjectId getObjectId()
If isValid()
returns false this method will return null.
public java.lang.String getNameString()
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.
public java.lang.String getPathString()
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.
ObjectId writeTree(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter ow) throws UnmergedPathException, java.io.IOException
cache
- the complete cache from DirCache.cIdx
- first position of cache
that is a member of this
tree. The path of cache[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 of cache[cacheIdx].path
that
matches this tree's path. The value at array position
cache[cacheIdx].path[pathOff-1]
is always '/' if
pathOff
is > 0.ow
- the writer to use when serializing to the store.UnmergedPathException
- one or more paths contain higher-order stages (stage > 0),
which cannot be stored in a tree object.java.io.IOException
- an unexpected error occurred writing to the object store.private int computeSize(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter ow) throws UnmergedPathException, java.io.IOException
UnmergedPathException
java.io.IOException
private void appendName(java.lang.StringBuilder r)
final int nameLength()
final boolean contains(byte[] a, int aOff, int aLen)
void validate(DirCacheEntry[] cache, int cCnt, int cIdx, int pathOff)
cache
- the complete cache from DirCache.cCnt
- number of entries in cache
that are valid for
iteration.cIdx
- first position of cache
that is a member of this
tree. The path of cache[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 of cache[cacheIdx].path
that
matches this tree's path. The value at array position
cache[cacheIdx].path[pathOff-1]
is always '/' if
pathOff
is > 0.private void insertChild(int stIdx, DirCacheTree st)
private void removeChild(int stIdx)
static boolean peq(byte[] a, byte[] b, int aLen)
private static int namecmp(byte[] a, int aPos, DirCacheTree ct)
private static int slash(byte[] a, int aPos)
public java.lang.String toString()
toString
in class java.lang.Object