Package org.eclipse.jgit.lib
Class CommitBuilder
java.lang.Object
org.eclipse.jgit.lib.ObjectBuilder
org.eclipse.jgit.lib.CommitBuilder
Mutable builder to construct a commit recording the state of a project.
Applications should use this object when they need to manually construct a
commit and want precise control over its fields. For a higher level interface
see
CommitCommand
.
To read a commit object, construct a RevWalk
and obtain a RevCommit
instance by calling
RevWalk.parseCommit(AnyObjectId)
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PersonIdent
private static final ObjectId[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private ObjectId[]
private ObjectId
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addParentId
(AnyObjectId additionalParent) Add a parent onto the end of the parent list.byte[]
build()
Format this builder's state as a git object.Get the author of this commit (who wrote it).Get the committer and commit time for this object.ObjectId[]
Get the ancestors of this commit.Get id of the root tree listing this commit's snapshot.void
setAuthor
(PersonIdent newAuthor) Set the author (name, email address, and date) of who wrote the commit.void
setCommitter
(PersonIdent newCommitter) Set the committer and commit time for this object.void
setEncoding
(String encodingName) Deprecated.void
setParentId
(AnyObjectId newParent) Set the parent of this commit.void
setParentIds
(List<? extends AnyObjectId> newParents) Set the parents of this commit.void
setParentIds
(AnyObjectId parent1, AnyObjectId parent2) Set the parents of this commit.void
setParentIds
(ObjectId... newParents) Set the parents of this commit.void
setTreeId
(AnyObjectId id) Set the tree id for this commit object.byte[]
Format this builder's state as a commit object.toString()
Methods inherited from class org.eclipse.jgit.lib.ObjectBuilder
getEncoding, getGpgSignature, getMessage, setEncoding, setGpgSignature, setMessage, writeEncoding, writeMultiLineHeader
-
Field Details
-
EMPTY_OBJECTID_LIST
-
htree
private static final byte[] htree -
hparent
private static final byte[] hparent -
hauthor
private static final byte[] hauthor -
hcommitter
private static final byte[] hcommitter -
hgpgsig
private static final byte[] hgpgsig -
treeId
-
parentIds
-
committer
-
-
Constructor Details
-
CommitBuilder
public CommitBuilder()Initialize an empty commit.
-
-
Method Details
-
getTreeId
Get id of the root tree listing this commit's snapshot.- Returns:
- id of the root tree listing this commit's snapshot.
-
setTreeId
Set the tree id for this commit object.- Parameters:
id
- the tree identity.
-
getAuthor
Get the author of this commit (who wrote it).- Overrides:
getAuthor
in classObjectBuilder
- Returns:
- the author of this commit (who wrote it).
-
setAuthor
Set the author (name, email address, and date) of who wrote the commit.- Overrides:
setAuthor
in classObjectBuilder
- Parameters:
newAuthor
- the new author. Should not be null.
-
getCommitter
Get the committer and commit time for this object.- Returns:
- the committer and commit time for this object.
-
setCommitter
Set the committer and commit time for this object.- Parameters:
newCommitter
- the committer information. Should not be null.
-
getParentIds
Get the ancestors of this commit.- Returns:
- the ancestors of this commit. Never null.
-
setParentId
Set the parent of this commit.- Parameters:
newParent
- the single parent for the commit.
-
setParentIds
Set the parents of this commit.- Parameters:
parent1
- the first parent of this commit. Typically this is the current value of theHEAD
reference and is thus the current branch's position in history.parent2
- the second parent of this merge commit. Usually this is the branch being merged into the current branch.
-
setParentIds
Set the parents of this commit.- Parameters:
newParents
- the entire list of parents for this commit.
-
setParentIds
Set the parents of this commit.- Parameters:
newParents
- the entire list of parents for this commit.
-
addParentId
Add a parent onto the end of the parent list.- Parameters:
additionalParent
- new parent to add onto the end of the current parent list.
-
setEncoding
Deprecated.useObjectBuilder.setEncoding(Charset)
instead.Set the encoding for the commit information.- Parameters:
encodingName
- the encoding name. SeeCharset.forName(String)
.
-
build
Description copied from class:ObjectBuilder
Format this builder's state as a git object.- Specified by:
build
in classObjectBuilder
- Returns:
- this object in the canonical git format, suitable for storage in a repository.
- Throws:
UnsupportedEncodingException
- the encoding specified byObjectBuilder.getEncoding()
is not supported by this Java runtime.
-
toByteArray
Format this builder's state as a commit object.- Returns:
- this object in the canonical commit format, suitable for storage in a repository.
- Throws:
UnsupportedEncodingException
- the encoding specified byObjectBuilder.getEncoding()
is not supported by this Java runtime.
-
toString
-
ObjectBuilder.setEncoding(Charset)
instead.