public class CommitBuilder
extends java.lang.Object
CommitCommand
.
To read a commit object, construct a RevWalk
and obtain a RevCommit
instance by calling
RevWalk.parseCommit(AnyObjectId)
.Modifier and Type | Field and Description |
---|---|
private PersonIdent |
author |
private PersonIdent |
committer |
private static ObjectId[] |
EMPTY_OBJECTID_LIST |
private java.nio.charset.Charset |
encoding |
private GpgSignature |
gpgSignature |
private static byte[] |
hauthor |
private static byte[] |
hcommitter |
private static byte[] |
hencoding |
private static byte[] |
hgpgsig |
private static byte[] |
hparent |
private static byte[] |
htree |
private java.lang.String |
message |
private ObjectId[] |
parentIds |
private ObjectId |
treeId |
Constructor and Description |
---|
CommitBuilder()
Initialize an empty commit.
|
Modifier and Type | Method and Description |
---|---|
void |
addParentId(AnyObjectId additionalParent)
Add a parent onto the end of the parent list.
|
byte[] |
build()
Format this builder's state as a commit object.
|
PersonIdent |
getAuthor()
Get the author of this commit (who wrote it).
|
PersonIdent |
getCommitter()
Get the committer and commit time for this object.
|
java.nio.charset.Charset |
getEncoding()
Get the encoding that should be used for the commit message text.
|
GpgSignature |
getGpgSignature()
Get the GPG signature of this commit.
|
java.lang.String |
getMessage()
Get the complete commit message.
|
ObjectId[] |
getParentIds()
Get the ancestors of this commit.
|
ObjectId |
getTreeId()
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(java.nio.charset.Charset enc)
Set the encoding for the commit information.
|
void |
setEncoding(java.lang.String encodingName)
Deprecated.
use
setEncoding(Charset) instead. |
void |
setGpgSignature(GpgSignature newSignature)
Set the GPG signature of this commit.
|
void |
setMessage(java.lang.String newMessage)
Set the commit message.
|
void |
setParentId(AnyObjectId newParent)
Set the parent of this commit.
|
void |
setParentIds(AnyObjectId parent1,
AnyObjectId parent2)
Set the parents of this commit.
|
void |
setParentIds(java.util.List<? extends AnyObjectId> newParents)
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[] |
toByteArray()
Format this builder's state as a commit object.
|
java.lang.String |
toString() |
(package private) static void |
writeGpgSignatureString(java.lang.String in,
java.io.OutputStream out)
Writes signature to output as per gpgsig
header.
|
private static final ObjectId[] EMPTY_OBJECTID_LIST
private static final byte[] htree
private static final byte[] hparent
private static final byte[] hauthor
private static final byte[] hcommitter
private static final byte[] hgpgsig
private static final byte[] hencoding
private ObjectId treeId
private ObjectId[] parentIds
private PersonIdent author
private PersonIdent committer
private GpgSignature gpgSignature
private java.lang.String message
private java.nio.charset.Charset encoding
public ObjectId getTreeId()
public void setTreeId(AnyObjectId id)
id
- the tree identity.public PersonIdent getAuthor()
public void setAuthor(PersonIdent newAuthor)
newAuthor
- the new author. Should not be null.public PersonIdent getCommitter()
public void setCommitter(PersonIdent newCommitter)
newCommitter
- the committer information. Should not be null.public void setGpgSignature(GpgSignature newSignature)
Note, the signature set here will change the payload of the commit, i.e.
the output of build()
will include the signature. Thus, the
typical flow will be:
build()
without a signature set to obtain payloadGpgSignature
from payloadGpgSignature
newSignature
- the signature to set or null
to unsetpublic GpgSignature getGpgSignature()
null
if the
commit is not to be signedpublic ObjectId[] getParentIds()
public void setParentId(AnyObjectId newParent)
newParent
- the single parent for the commit.public void setParentIds(AnyObjectId parent1, AnyObjectId parent2)
parent1
- the first parent of this commit. Typically this is the current
value of the HEAD
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.public void setParentIds(ObjectId... newParents)
newParents
- the entire list of parents for this commit.public void setParentIds(java.util.List<? extends AnyObjectId> newParents)
newParents
- the entire list of parents for this commit.public void addParentId(AnyObjectId additionalParent)
additionalParent
- new parent to add onto the end of the current parent list.public java.lang.String getMessage()
public void setMessage(java.lang.String newMessage)
newMessage
- the commit message. Should not be null.@Deprecated public void setEncoding(java.lang.String encodingName)
setEncoding(Charset)
instead.encodingName
- the encoding name. See
Charset.forName(String)
.public void setEncoding(java.nio.charset.Charset enc)
enc
- the encoding to use.public java.nio.charset.Charset getEncoding()
public byte[] build() throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
- the encoding specified by getEncoding()
is not
supported by this Java runtime.static void writeGpgSignatureString(java.lang.String in, java.io.OutputStream out) throws java.io.IOException, java.lang.IllegalArgumentException
CRLF and CR will be sanitized to LF and signature will have a hanging indent of one space starting with line two.
in
- signature string with line breaksout
- output streamjava.io.IOException
- thrown by the output streamjava.lang.IllegalArgumentException
- if the signature string contains non 7-bit ASCII charspublic byte[] toByteArray() throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
- the encoding specified by getEncoding()
is not
supported by this Java runtime.public java.lang.String toString()
toString
in class java.lang.Object