Top Description Fields Constructors Methods
org.eclipse.jgit.dircache

public Class DirCacheTree

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.lib.FileMode.TREE, .TreeFormatter.entrySize

Single tree record from the 'TREE' org.eclipse.jgit.dircache.DirCache extension.

A valid cache tree record contains the object id of a tree object and the total number of org.eclipse.jgit.dircache.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

Modifier and TypeField and Description
private int
childCnt

Number of valid children in children.

private DirCacheTree[]
children

Child trees, if any, sorted by encodedName.

pack-priv 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 final DirCacheTree[]
private static final byte[]
private DirCacheTree
parent

Tree this tree resides in; null if we are the root.

private static final Comparator<DirCacheTree>

Constructor Summary

AccessConstructor and Description
pack-priv
private
DirCacheTree(final DirCacheTree myParent, final byte[] path, final int pathOff, final int pathLen)

pack-priv
DirCacheTree(final byte[] in, final MutableInteger off, final DirCacheTree myParent)

Method Summary

Modifier and TypeMethod and Description
private void
private int
computeSize(final DirCacheEntry[] cache, int cIdx, final int pathOffset, final ObjectInserter ow)

pack-priv final boolean
contains(byte[] a, int aOff, int aLen)

public DirCacheTree

Returns:

the child tree.
getChild
(int
index of the child to obtain.
i
)

Get the i-th child cache tree.

public int

Returns:

number of child trees available through this tree.
getChildCount
()

Get the number of cached subtrees contained within this tree.

public int

Returns:

total number of entries (recursively) contained within this tree.
getEntrySpan
()

Get the number of entries this tree spans within the DirCache.

public String

Returns:

name of the tree. This does not contain any '/' characters.
getNameString
()

Get the tree's name within its parent.

public ObjectId

Returns:

ObjectId of this tree or null.
getObjectId
()

Get the tree's ObjectId.

public String

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 ("").
getPathString
()

Get the tree's path within the repository.

private void
insertChild(int stIdx, DirCacheTree st)

public boolean

Returns:

true if this tree is knows key details about itself; false if the tree needs to be regenerated.
isValid
()

Determine if this cache is currently valid.

private static int
namecmp(byte[] a, int aPos, DirCacheTree ct)

pack-priv final int
pack-priv static boolean
peq(byte[] a, byte[] b, int aLen)

private void
removeChild(int stIdx)

private static int
slash(byte[] a, int aPos)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
validate(final DirCacheEntry[]
the complete cache from DirCache.
cache
,
final int
number of entries in cache that are valid for iteration.
cCnt
,
int
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.
cIdx
,
final int
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.
pathOff
)

Update (if necessary) this tree's entrySpan.

pack-priv void
write(byte[] tmp, OutputStream os)

pack-priv ObjectId

Returns:

identity of this tree.
writeTree
(final DirCacheEntry[]
the complete cache from DirCache.
cache
,
int
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.
cIdx
,
final int
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.
pathOffset
,
final ObjectInserter
the writer to use when serializing to the store.
ow
)

Write (if necessary) this tree to the object store.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

childCntback to summary
private int childCnt

Number of valid children in children.

childrenback to summary
private DirCacheTree[] children

Child trees, if any, sorted by encodedName.

encodedNameback to summary
pack-priv byte[] encodedName

Name of this tree within its parent.

entrySpanback to summary
private int entrySpan

Number of DirCacheEntry records that belong to this tree.

idback to summary
private ObjectId id

Unique SHA-1 of this tree; null if invalid.

NO_CHILDRENback to summary
private static final DirCacheTree[] NO_CHILDREN
NO_NAMEback to summary
private static final byte[] NO_NAME
parentback to summary
private DirCacheTree parent

Tree this tree resides in; null if we are the root.

TREE_CMPback to summary
private static final Comparator<DirCacheTree> TREE_CMP

Constructor Detail

DirCacheTreeback to summary
pack-priv DirCacheTree()
DirCacheTreeback to summary
private DirCacheTree(final DirCacheTree myParent, final byte[] path, final int pathOff, final int pathLen)
DirCacheTreeback to summary
pack-priv DirCacheTree(final byte[] in, final MutableInteger off, final DirCacheTree myParent)

Method Detail

appendNameback to summary
private void appendName(StringBuilder r)
computeSizeback to summary
private int computeSize(final DirCacheEntry[] cache, int cIdx, final int pathOffset, final ObjectInserter ow) throws UnmergedPathException, IOException
containsback to summary
pack-priv final boolean contains(byte[] a, int aOff, int aLen)
getChildback to summary
public DirCacheTree getChild(int i)

Get the i-th child cache tree.

Parameters
i:int

index of the child to obtain.

Returns:DirCacheTree

the child tree.

getChildCountback to summary
public int getChildCount()

Get the number of cached subtrees contained within this tree.

Returns:int

number of child trees available through this tree.

getEntrySpanback to summary
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:int

total number of entries (recursively) contained within this tree.

getNameStringback to summary
public String 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:String

name of the tree. This does not contain any '/' characters.

getObjectIdback to summary
public ObjectId getObjectId()

Get the tree's ObjectId.

If isValid() returns false this method will return null.

Returns:ObjectId

ObjectId of this tree or null.

Since
4.3
getPathStringback to summary
public String 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:String

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 ("").

insertChildback to summary
private void insertChild(int stIdx, DirCacheTree st)
isValidback to summary
public boolean isValid()

Determine if this cache is currently valid.

A valid cache tree knows how many org.eclipse.jgit.dircache.DirCacheEntry instances from the parent org.eclipse.jgit.dircache.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.

Returns:boolean

true if this tree is knows key details about itself; false if the tree needs to be regenerated.

namecmpback to summary
private static int namecmp(byte[] a, int aPos, DirCacheTree ct)
nameLengthback to summary
pack-priv final int nameLength()
peqback to summary
pack-priv static boolean peq(byte[] a, byte[] b, int aLen)
removeChildback to summary
private void removeChild(int stIdx)
slashback to summary
private static int slash(byte[] a, int aPos)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
validateback to summary
pack-priv void validate(final DirCacheEntry[] cache, final int cCnt, int cIdx, final int pathOff)

Update (if necessary) this tree's entrySpan.

Parameters
cache:DirCacheEntry[]

the complete cache from DirCache.

cCnt:int

number of entries in cache that are valid for iteration.

cIdx:int

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:int

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.

writeback to summary
pack-priv void write(byte[] tmp, OutputStream os) throws IOException
writeTreeback to summary
pack-priv ObjectId writeTree(final DirCacheEntry[] cache, int cIdx, final int pathOffset, final ObjectInserter ow) throws UnmergedPathException, IOException

Write (if necessary) this tree to the object store.

Parameters
cache:DirCacheEntry[]

the complete cache from DirCache.

cIdx:int

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:int

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:ObjectInserter

the writer to use when serializing to the store.

Returns:ObjectId

identity of this tree.

Exceptions
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.