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

public Class TreeFormatter

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH, .Constants.OBJ_TREE, .Constants.encode, .FileMode.GITLINK, .FileMode.REGULAR_FILE, .FileMode.TREE

Mutable formatter to construct a single tree object. This formatter does not process subtrees. Callers must handle creating each subtree on their own. To maintain good performance for bulk operations, this formatter does not validate its input. Callers are responsible for ensuring the resulting tree object is correctly well formed by writing entries in the correct order.

Field Summary

Modifier and TypeField and Description
private byte[]
private TemporaryBuffer.Heap
private int

Constructor Summary

AccessConstructor and Description
public
TreeFormatter()

Create an empty formatter with a default buffer size.

public
TreeFormatter(int
estimated size of the tree, in bytes. Callers can use entrySize(FileMode, int) to estimate the size of each entry in advance of allocating the formatter.
size
)

Create an empty formatter with the specified buffer size.

Method Summary

Modifier and TypeMethod and Description
public void
append(String
name of the entry.
name
,
RevCommit
the ObjectId to store in this entry.
commit
)

Add a link to a submodule commit, mode is org.eclipse.jgit.lib.FileMode#GITLINK.

public void
append(String
name of the entry.
name
,
RevTree
the ObjectId to store in this entry.
tree
)

Add a subtree, mode is org.eclipse.jgit.lib.FileMode#TREE.

public void
append(String
name of the entry.
name
,
RevBlob
the ObjectId to store in this entry.
blob
)

Add a regular file, mode is org.eclipse.jgit.lib.FileMode#REGULAR_FILE.

public void
append(String
name of the entry.
name
,
FileMode
mode describing the treatment of id.
mode
,
AnyObjectId
the ObjectId to store in this entry.
id
)

Append any entry to the tree.

public void
append(byte[]
name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.
name
,
FileMode
mode describing the treatment of id.
mode
,
AnyObjectId
the ObjectId to store in this entry.
id
)

Append any entry to the tree.

public void
append(byte[]
buffer holding the name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.
nameBuf
,
int
first position within nameBuf of the name data.
namePos
,
int
number of bytes from nameBuf to use as the name.
nameLen
,
FileMode
mode describing the treatment of id.
mode
,
AnyObjectId
the ObjectId to store in this entry.
id
)

Append any entry to the tree.

public void
append(byte[]
buffer holding the name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.
nameBuf
,
int
first position within nameBuf of the name data.
namePos
,
int
number of bytes from nameBuf to use as the name.
nameLen
,
FileMode
mode describing the treatment of id.
mode
,
AnyObjectId
the ObjectId to store in this entry.
id
,
boolean
allow an empty filename (creating a corrupt tree)
allowEmptyName
)

Append any entry to the tree.

public void
append(byte[]
buffer holding the name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.
nameBuf
,
int
first position within nameBuf of the name data.
namePos
,
int
number of bytes from nameBuf to use as the name.
nameLen
,
FileMode
mode describing the treatment of id.
mode
,
byte[]
buffer holding the raw ObjectId of the entry.
idBuf
,
int
first position within idBuf to copy the id from.
idPos
)

Append any entry to the tree.

public ObjectId

Returns:

ObjectId for this tree
computeId
(ObjectInserter ins)

Compute the ObjectId for this tree

public static int

Returns:

the length of the record.
entrySize
(FileMode
the mode the entry will have.
mode
,
int
the length of the name, in bytes.
nameLen
)

Compute the size of a tree entry record.

private boolean
fmtBuf(byte[] nameBuf, int namePos, int nameLen, FileMode mode)

private void
fmtOverflowBuffer(byte[] nameBuf, int namePos, int nameLen, FileMode mode)

public ObjectId

Returns:

computed ObjectId of the tree
insertTo
(ObjectInserter
the inserter to store the tree.
ins
)

Insert this tree and obtain its ObjectId.

public byte[]

Returns:

a copy of this formatter's buffer.
toByteArray
()

Copy this formatter's buffer into a byte array.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufback to summary
private byte[] buf
overflowBufferback to summary
private TemporaryBuffer.Heap overflowBuffer
ptrback to summary
private int ptr

Constructor Detail

TreeFormatterback to summary
public TreeFormatter()

Create an empty formatter with a default buffer size.

TreeFormatterback to summary
public TreeFormatter(int size)

Create an empty formatter with the specified buffer size.

Parameters
size:int

estimated size of the tree, in bytes. Callers can use entrySize(FileMode, int) to estimate the size of each entry in advance of allocating the formatter.

Method Detail

appendback to summary
public void append(String name, RevCommit commit)

Add a link to a submodule commit, mode is org.eclipse.jgit.lib.FileMode#GITLINK.

Parameters
name:String

name of the entry.

commit:RevCommit

the ObjectId to store in this entry.

appendback to summary
public void append(String name, RevTree tree)

Add a subtree, mode is org.eclipse.jgit.lib.FileMode#TREE.

Parameters
name:String

name of the entry.

tree:RevTree

the ObjectId to store in this entry.

appendback to summary
public void append(String name, RevBlob blob)

Add a regular file, mode is org.eclipse.jgit.lib.FileMode#REGULAR_FILE.

Parameters
name:String

name of the entry.

blob:RevBlob

the ObjectId to store in this entry.

appendback to summary
public void append(String name, FileMode mode, AnyObjectId id)

Append any entry to the tree.

Parameters
name:String

name of the entry.

mode:FileMode

mode describing the treatment of id.

id:AnyObjectId

the ObjectId to store in this entry.

appendback to summary
public void append(byte[] name, FileMode mode, AnyObjectId id)

Append any entry to the tree.

Parameters
name:byte[]

name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.

mode:FileMode

mode describing the treatment of id.

id:AnyObjectId

the ObjectId to store in this entry.

appendback to summary
public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, AnyObjectId id)

Append any entry to the tree.

Parameters
nameBuf:byte[]

buffer holding the name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.

namePos:int

first position within nameBuf of the name data.

nameLen:int

number of bytes from nameBuf to use as the name.

mode:FileMode

mode describing the treatment of id.

id:AnyObjectId

the ObjectId to store in this entry.

appendback to summary
public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, AnyObjectId id, boolean allowEmptyName)

Append any entry to the tree.

Parameters
nameBuf:byte[]

buffer holding the name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.

namePos:int

first position within nameBuf of the name data.

nameLen:int

number of bytes from nameBuf to use as the name.

mode:FileMode

mode describing the treatment of id.

id:AnyObjectId

the ObjectId to store in this entry.

allowEmptyName:boolean

allow an empty filename (creating a corrupt tree)

Since
4.6
appendback to summary
public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, byte[] idBuf, int idPos)

Append any entry to the tree.

Parameters
nameBuf:byte[]

buffer holding the name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.

namePos:int

first position within nameBuf of the name data.

nameLen:int

number of bytes from nameBuf to use as the name.

mode:FileMode

mode describing the treatment of id.

idBuf:byte[]

buffer holding the raw ObjectId of the entry.

idPos:int

first position within idBuf to copy the id from.

computeIdback to summary
public ObjectId computeId(ObjectInserter ins)

Compute the ObjectId for this tree

Parameters
ins:ObjectInserter

a org.eclipse.jgit.lib.ObjectInserter object.

Returns:ObjectId

ObjectId for this tree

entrySizeback to summary
public static int entrySize(FileMode mode, int nameLen)

Compute the size of a tree entry record. This method can be used to estimate the correct size of a tree prior to allocating a formatter. Getting the size correct at allocation time ensures the internal buffer is sized correctly, reducing copying.

Parameters
mode:FileMode

the mode the entry will have.

nameLen:int

the length of the name, in bytes.

Returns:int

the length of the record.

fmtBufback to summary
private boolean fmtBuf(byte[] nameBuf, int namePos, int nameLen, FileMode mode)
fmtOverflowBufferback to summary
private void fmtOverflowBuffer(byte[] nameBuf, int namePos, int nameLen, FileMode mode) throws IOException
insertToback to summary
public ObjectId insertTo(ObjectInserter ins) throws IOException

Insert this tree and obtain its ObjectId.

Parameters
ins:ObjectInserter

the inserter to store the tree.

Returns:ObjectId

computed ObjectId of the tree

Exceptions
IOException:
the tree could not be stored.
toByteArrayback to summary
public byte[] toByteArray()

Copy this formatter's buffer into a byte array. This method is not efficient, as it needs to create a copy of the internal buffer in order to supply an array of the correct size to the caller. If the buffer is just to pass to an ObjectInserter, consider using org.eclipse.jgit.lib.ObjectInserter#insert(TreeFormatter) instead.

Returns:byte[]

a copy of this formatter's buffer.

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
@SuppressWarnings:nls
@Override