org.eclipse.jgit.revwalk
Class RevCommit

java.lang.Object
  extended by org.eclipse.jgit.lib.AnyObjectId
      extended by org.eclipse.jgit.lib.ObjectId
          extended by org.eclipse.jgit.revwalk.RevObject
              extended by org.eclipse.jgit.revwalk.RevCommit
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
PlotCommit

public class RevCommit
extends RevObject

A commit reference to a commit in the DAG.


Constructor Summary
protected RevCommit(AnyObjectId id)
          Create a new commit reference.
 
Method Summary
 Commit asCommit(RevWalk walk)
          Parse this commit buffer for display.
 void carry(RevFlag flag)
          Carry a RevFlag set on this commit to its parents.
 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.
 java.nio.charset.Charset getEncoding()
          Determine the encoding of the commit message buffer.
 java.util.List<FooterLine> getFooterLines()
          Parse the footer lines (e.g.
 java.util.List<java.lang.String> getFooterLines(FooterKey keyName)
          Get the values of all footer lines with the given key.
 java.util.List<java.lang.String> getFooterLines(java.lang.String keyName)
          Get the values of all footer lines with the given key.
 java.lang.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).
 java.lang.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.
 void reset()
          Reset this commit to allow another RevWalk with the same instances.
 java.lang.String toString()
           
 
Methods inherited from class org.eclipse.jgit.revwalk.RevObject
add, add, appendCoreFlags, equals, equals, getId, has, hasAll, hasAny, remove, remove
 
Methods inherited from class org.eclipse.jgit.lib.ObjectId
equals, fromRaw, fromRaw, fromRaw, fromRaw, fromString, fromString, isId, toObjectId, toString, zeroId
 
Methods inherited from class org.eclipse.jgit.lib.AnyObjectId
abbreviate, abbreviate, compareTo, compareTo, copy, copyRawTo, copyRawTo, copyRawTo, copyRawTo, copyTo, copyTo, copyTo, copyTo, equals, getFirstByte, getName, hashCode, name, startsWith
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RevCommit

protected RevCommit(AnyObjectId id)
Create a new commit reference.

Parameters:
id - object name for the commit.
Method Detail

getType

public final int getType()
Description copied from class: RevObject
Get Git object type. See Constants.

Specified by:
getType in class RevObject
Returns:
object type

carry

public void carry(RevFlag flag)
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:
time, expressed as seconds since the epoch.

asCommit

public final Commit asCommit(RevWalk walk)
Parse this commit buffer for display.

Parameters:
walk - revision walker owning this reference.
Returns:
parsed commit.

getTree

public final RevTree 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

public final RevCommit getParent(int nth)
Get the nth parent from this commit's parent list.

Parameters:
nth - parent index to obtain. Must be in the range 0 through getParentCount()-1.
Returns:
the specified parent.
Throws:
java.lang.ArrayIndexOutOfBoundsException - an invalid parent index was specified.

getParents

public final RevCommit[] 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.

getAuthorIdent

public final PersonIdent 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 RawParseUtils to scan the getRawBuffer() 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

public final PersonIdent 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 RawParseUtils to scan the getRawBuffer() 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

public final java.lang.String 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

public final java.lang.String 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.

getEncoding

public final java.nio.charset.Charset 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, Constants.CHARSET is assumed.

Returns:
the preferred encoding of getRawBuffer().

getFooterLines

public final java.util.List<FooterLine> getFooterLines()
Parse the footer lines (e.g. "Signed-off-by") for machine processing.

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:

Returns:
ordered list of footer lines; empty list if no footers found.

getFooterLines

public final java.util.List<java.lang.String> getFooterLines(java.lang.String keyName)
Get the values of all footer lines with the given key.

Parameters:
keyName - footer key to find values of, case insensitive.
Returns:
values of footers with key of 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.
See Also:
getFooterLines()

getFooterLines

public final java.util.List<java.lang.String> getFooterLines(FooterKey keyName)
Get the values of all footer lines with the given key.

Parameters:
keyName - footer key to find values of, case insensitive.
Returns:
values of footers with key of 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.
See Also:
getFooterLines()

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.


toString

public java.lang.String toString()
Overrides:
toString in class RevObject