Class RevCommit
- All Implemented Interfaces:
Serializable,Comparable<AnyObjectId>
- Direct Known Subclasses:
DepthWalk.Commit,NameRevCommand.NameRevCommit,PlotCommit,ReverseWalk.ReverseCommit
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCarry a RevFlag set on this commit to its parents.(package private) static voidcarryFlags(RevCommit c, int carry) private static FIFORevQueuecarryFlags1(RevCommit c, int carry, int depth) private static voidcarryOneStep(FIFORevQueue q, int carry, RevCommit c) private static FIFORevQueuedefer(FIFORevQueue q, int carry, RevCommit[] pList, int i) private static FIFORevQueuefinal voidDiscard the message buffer to reduce memory usage.final PersonIdentParse the author identity from the raw buffer.final PersonIdentParse the committer identity from the raw buffer.final intTime from the "committer " line of the buffer.final CharsetDetermine the encoding of the commit message buffer.final StringDetermine the encoding of the commit message buffer.final List<FooterLine>Parse the footer lines (e.g.getFooterLines(String keyName) Get the values of all footer lines with the given key.getFooterLines(FooterKey keyName) Get the values of all footer lines with the given key.final StringParse the complete commit message and decode it to a string.final RevCommitgetParent(int nth) Get the nth parent from this commit's parent list.final intGet the number of parent commits listed in this commit.final RevCommit[]Obtain an array of all parents (NOTE - THIS IS NOT A COPY).final byte[]Obtain the raw unparsed commit body (NOTE - THIS IS NOT A COPY).final byte[]Parse the gpg signature from the raw buffer.final StringParse the commit message and return the first "line" of it.final RevTreegetTree()Get a reference to this commit's tree.final intgetType()Get Git object type.private Charset(package private) static booleanhasLF(byte[] r, int b, int e) static RevCommitparse(byte[] raw) Parse a commit from its canonical format.static RevCommitParse a commit from its canonical format.(package private) void(package private) voidparseCanonical(RevWalk walk, byte[] raw) (package private) voidparseHeaders(RevWalk walk) voidreset()Reset this commit to allow another RevWalk with the same instances.private static voidslowCarryFlags(FIFORevQueue q, int carry) toString()Methods inherited from class org.eclipse.jgit.revwalk.RevObject
add, add, appendCoreFlags, getId, has, hasAll, hasAny, remove, removeMethods inherited from class org.eclipse.jgit.lib.ObjectId
equals, fromRaw, fromRaw, fromRaw, fromRaw, fromString, fromString, isId, toObjectId, toString, zeroId
-
Field Details
-
STACK_DEPTH
private static final int STACK_DEPTH- See Also:
-
NO_PARENTS
-
tree
-
parents
RevCommit[] parents -
commitTime
int commitTime -
inDegree
int inDegree -
buffer
private byte[] buffer
-
-
Constructor Details
-
RevCommit
Create a new commit reference.- Parameters:
id- object name for the commit.
-
-
Method Details
-
parse
Parse a commit from its canonical format. This method constructs a temporary revision pool, parses the commit as supplied, and returns it to the caller. Since the commit was built inside of a private revision pool its parent pointers will be initialized, but will not have their headers loaded. Applications are discouraged from using this API. Callers usually need more than one commit. UseRevWalk.parseCommit(AnyObjectId)to obtain a RevCommit from an existing repository.- Parameters:
raw- the canonical formatted commit to be parsed.- Returns:
- the parsed commit, in an isolated revision pool that is not available to the caller.
-
parse
Parse a commit from its canonical format.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 suppliedRevWalkhas been configured withsetRetainBody(false).- Parameters:
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 returnedRevCommitand must not be modified by the caller.- Returns:
- the parsed commit, in an isolated revision pool that is not available to the caller.
- Throws:
IOException- in case of RevWalk initialization fails
-
parseHeaders
void parseHeaders(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException - Specified by:
parseHeadersin classRevObject- Throws:
MissingObjectExceptionIncorrectObjectTypeExceptionIOException
-
parseBody
void parseBody(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException - Specified by:
parseBodyin classRevObject- Throws:
MissingObjectExceptionIncorrectObjectTypeExceptionIOException
-
parseCanonical
- Throws:
IOException
-
getType
public final int getType()Get Git object type. SeeConstants. -
carryFlags
-
carryFlags1
-
defer
-
defer
-
slowCarryFlags
-
carryOneStep
-
carry
Carry a RevFlag set on this commit to its parents.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.
- Parameters:
flag- the single flag value to carry back onto parents.
-
getCommitTime
public final int getCommitTime()Time from the "committer " line of the buffer.- Returns:
- commit time
-
getTree
Get a reference to this commit's tree.- Returns:
- tree of this commit.
-
getParentCount
public final int getParentCount()Get the number of parent commits listed in this commit.- Returns:
- number of parents; always a positive value but can be 0.
-
getParent
Get the nth parent from this commit's parent list.- Parameters:
nth- parent index to obtain. Must be in the range 0 throughgetParentCount()-1.- Returns:
- the specified parent.
- Throws:
ArrayIndexOutOfBoundsException- an invalid parent index was specified.
-
getParents
Obtain an array of all parents (NOTE - THIS IS NOT A COPY).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.
- Returns:
- the array of parents.
-
getRawBuffer
public final byte[] getRawBuffer()Obtain the raw unparsed commit body (NOTE - THIS IS NOT A COPY).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.
- Returns:
- the raw unparsed commit body. This is NOT A COPY. Altering the contents of this buffer may alter the walker's knowledge of this commit, and the results it produces.
-
getRawGpgSignature
public final byte[] getRawGpgSignature()Parse the gpg signature from the raw buffer.This method parses and returns the raw content of the gpgsig lines. This method is fairly expensive and produces a new byte[] instance on each invocation. Callers should invoke this method only if they are certain they will need, and should cache the return value for as long as necessary to use all information from it.
RevFilter implementations should try to use
RawParseUtilsto scan thegetRawBuffer()instead, as this will allow faster evaluation of commits.- Returns:
- contents of the gpg signature; null if the commit was not signed.
- Since:
- 5.1
-
getAuthorIdent
Parse the author identity from the raw buffer.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
RawParseUtilsto scan thegetRawBuffer()instead, as this will allow faster evaluation of commits.- Returns:
- identity of the author (name, email) and the time the commit was made by the author; null if no author line was found.
-
getCommitterIdent
Parse the committer identity from the raw buffer.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
RawParseUtilsto scan thegetRawBuffer()instead, as this will allow faster evaluation of commits.- Returns:
- identity of the committer (name, email) and the time the commit was made by the committer; null if no committer line was found.
-
getFullMessage
Parse the complete commit message and decode it to a string.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.
- Returns:
- decoded commit message as a string. Never null.
-
getShortMessage
Parse the commit message and return the first "line" of it.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.
- Returns:
- decoded commit message as a string. Never null. The returned string does not contain any LFs, even if the first paragraph spanned multiple lines. Embedded LFs are converted to spaces.
-
hasLF
static boolean hasLF(byte[] r, int b, int e) -
getEncodingName
Determine the encoding of the commit message buffer.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.
- Returns:
- the preferred encoding of
getRawBuffer(); or null. - Since:
- 4.2
-
getEncoding
Determine the encoding of the commit message buffer.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-8is assumed.- Returns:
- the preferred encoding of
getRawBuffer(). - Throws:
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.
-
guessEncoding
-
reset
public void reset()Reset this commit to allow another RevWalk with the same instances.Subclasses must call
super.reset()to ensure the basic information can be correctly cleared out. -
disposeBody
public final void disposeBody()Discard the message buffer to reduce memory usage.After discarding the memory usage of the
RevCommitis reduced to only thegetTree()andgetParents()pointers and the time ingetCommitTime(). Accessing other properties such asgetAuthorIdent(),getCommitterIdent()or either message function requires reloading the buffer by invokingRevWalk.parseBody(RevObject).- Since:
- 4.0
-
toString
-