Package org.eclipse.jgit.lib
Class TreeFormatter
java.lang.Object
org.eclipse.jgit.lib.TreeFormatter
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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty formatter with a default buffer size.TreeFormatter
(int size) Create an empty formatter with the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Append any entry to the tree.void
append
(byte[] nameBuf, int namePos, int nameLen, FileMode mode, AnyObjectId id) Append any entry to the tree.void
append
(byte[] nameBuf, int namePos, int nameLen, FileMode mode, AnyObjectId id, boolean allowEmptyName) Append any entry to the tree.void
append
(byte[] name, FileMode mode, AnyObjectId id) Append any entry to the tree.void
append
(String name, FileMode mode, AnyObjectId id) Append any entry to the tree.void
Add a regular file, mode isFileMode.REGULAR_FILE
.void
Add a link to a submodule commit, mode isFileMode.GITLINK
.void
Add a subtree, mode isFileMode.TREE
.computeId
(ObjectInserter ins) Compute the ObjectId for this treestatic int
Compute the size of a tree entry record.private boolean
private void
fmtOverflowBuffer
(byte[] nameBuf, int namePos, int nameLen, FileMode mode) insertTo
(ObjectInserter ins) Insert this tree and obtain its ObjectId.byte[]
Copy this formatter's buffer into a byte array.toString()
-
Field Details
-
buf
private byte[] buf -
ptr
private int ptr -
overflowBuffer
-
-
Constructor Details
-
TreeFormatter
public TreeFormatter()Create an empty formatter with a default buffer size. -
TreeFormatter
public TreeFormatter(int size) Create an empty formatter with the specified buffer size.- Parameters:
size
- estimated size of the tree, in bytes. Callers can useentrySize(FileMode, int)
to estimate the size of each entry in advance of allocating the formatter.
-
-
Method Details
-
entrySize
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
- the mode the entry will have.nameLen
- the length of the name, in bytes.- Returns:
- the length of the record.
-
append
Add a link to a submodule commit, mode isFileMode.GITLINK
.- Parameters:
name
- name of the entry.commit
- the ObjectId to store in this entry.
-
append
Add a subtree, mode isFileMode.TREE
.- Parameters:
name
- name of the entry.tree
- the ObjectId to store in this entry.
-
append
Add a regular file, mode isFileMode.REGULAR_FILE
.- Parameters:
name
- name of the entry.blob
- the ObjectId to store in this entry.
-
append
Append any entry to the tree.- Parameters:
name
- name of the entry.mode
- mode describing the treatment ofid
.id
- the ObjectId to store in this entry.
-
append
Append any entry to the tree.- Parameters:
name
- name of the entry. The name should be UTF-8 encoded, but file name encoding is not a well defined concept in Git.mode
- mode describing the treatment ofid
.id
- the ObjectId to store in this entry.
-
append
Append any entry to the tree.- Parameters:
nameBuf
- 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
- first position withinnameBuf
of the name data.nameLen
- number of bytes fromnameBuf
to use as the name.mode
- mode describing the treatment ofid
.id
- the ObjectId to store in this entry.
-
append
public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, AnyObjectId id, boolean allowEmptyName) Append any entry to the tree.- Parameters:
nameBuf
- 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
- first position withinnameBuf
of the name data.nameLen
- number of bytes fromnameBuf
to use as the name.mode
- mode describing the treatment ofid
.id
- the ObjectId to store in this entry.allowEmptyName
- allow an empty filename (creating a corrupt tree)- Since:
- 4.6
-
append
public void append(byte[] nameBuf, int namePos, int nameLen, FileMode mode, byte[] idBuf, int idPos) Append any entry to the tree.- Parameters:
nameBuf
- 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
- first position withinnameBuf
of the name data.nameLen
- number of bytes fromnameBuf
to use as the name.mode
- mode describing the treatment ofid
.idBuf
- buffer holding the raw ObjectId of the entry.idPos
- first position withinidBuf
to copy the id from.
-
fmtBuf
-
fmtOverflowBuffer
private void fmtOverflowBuffer(byte[] nameBuf, int namePos, int nameLen, FileMode mode) throws IOException - Throws:
IOException
-
insertTo
Insert this tree and obtain its ObjectId.- Parameters:
ins
- the inserter to store the tree.- Returns:
- computed ObjectId of the tree
- Throws:
IOException
- the tree could not be stored.
-
computeId
Compute the ObjectId for this tree- Parameters:
ins
- aObjectInserter
object.- Returns:
- ObjectId for this tree
-
toByteArray
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 usingObjectInserter.insert(TreeFormatter)
instead.- Returns:
- a copy of this formatter's buffer.
-
toString
-