public class RevCommit extends RevObject
Modifier | Constructor and Description |
---|---|
protected |
RevCommit(AnyObjectId id)
Create a new commit reference.
|
Modifier and Type | Method and Description |
---|---|
void |
carry(RevFlag flag)
Carry a RevFlag set on this commit to its parents.
|
void |
disposeBody()
Discard the message buffer to reduce memory usage.
|
PersonIdent |
getAuthorIdent()
Parse the author identity from the raw buffer.
|
PersonIdent |
getCommitterIdent()
Parse the committer identity from the raw buffer.
|
int |
getCommitTime()
Time from the "committer " line of the buffer.
|
Charset |
getEncoding()
Determine the encoding of the commit message buffer.
|
String |
getEncodingName()
Determine the encoding of the commit message buffer.
|
List<FooterLine> |
getFooterLines()
Parse the footer lines (e.g.
|
List<String> |
getFooterLines(FooterKey keyName)
Get the values of all footer lines with the given key.
|
List<String> |
getFooterLines(String keyName)
Get the values of all footer lines with the given key.
|
String |
getFullMessage()
Parse the complete commit message and decode it to a string.
|
RevCommit |
getParent(int nth)
Get the nth parent from this commit's parent list.
|
int |
getParentCount()
Get the number of parent commits listed in this commit.
|
RevCommit[] |
getParents()
Obtain an array of all parents (NOTE - THIS IS NOT A COPY).
|
byte[] |
getRawBuffer()
Obtain the raw unparsed commit body (NOTE - THIS IS NOT A COPY).
|
String |
getShortMessage()
Parse the commit message and return the first "line" of it.
|
RevTree |
getTree()
Get a reference to this commit's tree.
|
int |
getType()
Get Git object type.
|
static RevCommit |
parse(byte[] raw)
Parse a commit from its canonical format.
|
static RevCommit |
parse(RevWalk rw,
byte[] raw)
Parse a commit from its canonical format.
|
void |
reset()
Reset this commit to allow another RevWalk with the same instances.
|
String |
toString() |
add, add, appendCoreFlags, getId, has, hasAll, hasAny, remove, remove
equals, fromRaw, fromRaw, fromRaw, fromRaw, fromString, fromString, isId, toObjectId, toString, zeroId
protected RevCommit(AnyObjectId id)
id
- object name for the commit.public static RevCommit parse(byte[] raw)
RevWalk.parseCommit(AnyObjectId)
to
obtain a RevCommit from an existing repository.raw
- the canonical formatted commit to be parsed.public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException
This method inserts the commit directly into the caller supplied revision pool, making it appear as though the commit exists in the repository, even if it doesn't. The repository under the pool is not affected.
The body of the commit (message, author, committer) is always retained in
the returned RevCommit
, even if the supplied RevWalk
has
been configured with setRetainBody(false)
.
rw
- the revision pool to allocate the commit within. The commit's
tree and parent pointers will be obtained from this pool.raw
- the canonical formatted commit to be parsed. This buffer will
be retained by the returned RevCommit
and must not be
modified by the caller.IOException
- in case of RevWalk initialization failspublic final int getType()
RevObject
Constants
.public void carry(RevFlag flag)
If this commit is parsed, has parents, and has the supplied flag set on it we automatically add it to the parents, grand-parents, and so on until an unparsed commit or a commit with no parents is discovered. This permits applications to force a flag through the history chain when necessary.
flag
- the single flag value to carry back onto parents.public final int getCommitTime()
public final RevTree getTree()
public final int getParentCount()
public final RevCommit getParent(int nth)
nth
- parent index to obtain. Must be in the range 0 through
getParentCount()
-1.ArrayIndexOutOfBoundsException
- an invalid parent index was specified.public final RevCommit[] getParents()
This method is exposed only to provide very fast, efficient access to this commit's parent list. Applications relying on this list should be very careful to ensure they do not modify its contents during their use of it.
public final byte[] getRawBuffer()
This method is exposed only to provide very fast, efficient access to this commit's message buffer within a RevFilter. Applications relying on this buffer should be very careful to ensure they do not modify its contents during their use of it.
public final PersonIdent getAuthorIdent()
This method parses and returns the content of the author line, after taking the commit's character set into account and decoding the author name and email address. This method is fairly expensive and produces a new PersonIdent instance on each invocation. Callers should invoke this method only if they are certain they will be outputting the result, and should cache the return value for as long as necessary to use all information from it.
RevFilter implementations should try to use RawParseUtils
to scan
the getRawBuffer()
instead, as this will allow faster evaluation
of commits.
public final PersonIdent getCommitterIdent()
This method parses and returns the content of the committer line, after taking the commit's character set into account and decoding the committer name and email address. This method is fairly expensive and produces a new PersonIdent instance on each invocation. Callers should invoke this method only if they are certain they will be outputting the result, and should cache the return value for as long as necessary to use all information from it.
RevFilter implementations should try to use RawParseUtils
to scan
the getRawBuffer()
instead, as this will allow faster evaluation
of commits.
public final String getFullMessage()
This method parses and returns the message portion of the commit buffer, after taking the commit's character set into account and decoding the buffer using that character set. This method is a fairly expensive operation and produces a new string on each invocation.
public final String getShortMessage()
The first line is everything up to the first pair of LFs. This is the "oneline" format, suitable for output in a single line display.
This method parses and returns the message portion of the commit buffer, after taking the commit's character set into account and decoding the buffer using that character set. This method is a fairly expensive operation and produces a new string on each invocation.
@Nullable public final String getEncodingName()
Locates the "encoding" header (if present) and returns its value. Due to corruption in the wild this may be an invalid encoding name that is not recognized by any character encoding library.
If no encoding header is present, null.
getRawBuffer()
; or null.public final Charset getEncoding()
Locates the "encoding" header (if present) and then returns the proper character set to apply to this buffer to evaluate its contents as character data.
If no encoding header is present UTF-8
is assumed.
getRawBuffer()
.IllegalCharsetNameException
- if the character set requested by the encoding header is
malformed and unsupportable.UnsupportedCharsetException
- if the JRE does not support the character set requested by
the encoding header.public final List<FooterLine> getFooterLines()
This method splits all of the footer lines out of the last paragraph of the commit message, providing each line as a key-value pair, ordered by the order of the line's appearance in the commit message itself.
A footer line's key must match the pattern ^[A-Za-z0-9-]+:
, while
the value is free-form, but must not contain an LF. Very common keys seen
in the wild are:
Signed-off-by
(agrees to Developer Certificate of Origin)
Acked-by
(thinks change looks sane in context)
Reported-by
(originally found the issue this change fixes)
Tested-by
(validated change fixes the issue for them)
CC
, Cc
(copy on all email related to this change)
Bug
(link to project's bug tracking system)
public final List<String> getFooterLines(String keyName)
keyName
- footer key to find values of, case insensitive.keyName
, ordered by their
order of appearance. Duplicates may be returned if the same
footer appeared more than once. Empty list if no footers appear
with the specified key, or there are no footers at all.getFooterLines()
public final List<String> getFooterLines(FooterKey keyName)
keyName
- footer key to find values of, case insensitive.keyName
, ordered by their
order of appearance. Duplicates may be returned if the same
footer appeared more than once. Empty list if no footers appear
with the specified key, or there are no footers at all.getFooterLines()
public void reset()
Subclasses must call super.reset()
to ensure the
basic information can be correctly cleared out.
public final void disposeBody()
After discarding the memory usage of the RevCommit
is reduced to
only the getTree()
and getParents()
pointers and the
time in getCommitTime()
. Accessing other properties such as
getAuthorIdent()
, getCommitterIdent()
or either message
function requires reloading the buffer by invoking
RevWalk.parseBody(RevObject)
.
Copyright © 2017 Eclipse JGit Project. All rights reserved.