Package org.eclipse.jgit.api
Class LogCommand
A class used to execute a
Log
command. It has setters for all
supported options and arguments of this command and a call()
method
to finally execute the command. Each instance of this class should only be
used for one invocation of the command (means: one call to call()
)
Examples (git
is a Git
instance):
Get newest 10 commits, starting from the current branch:
ObjectId head = repository.resolve(Constants.HEAD); Iterable<RevCommit> commits = git.log().add(head).setMaxCount(10).call();
Get commits only for a specific file:
git.log().add(head).addPath("dir/filename.txt").call();
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<TreeFilter> private int
private final List
<PathFilter> private RevFilter
private int
private boolean
private RevWalk
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate LogCommand
add
(boolean include, AnyObjectId start) add
(AnyObjectId start) Mark a commit to start graph traversal from.Show only commits that affect any of the specified paths.addRange
(AnyObjectId since, AnyObjectId until) Adds the rangesince..until
all()
Add all refs as commits to start the graph traversal from.call()
excludePath
(String path) Show all commits that are not within any of the specified paths.not
(AnyObjectId start) Same as--not start
, or^start
setMaxCount
(int maxCount) Limit the number of commits to output.setRevFilter
(RevFilter aFilter) Set a filter for theLogCommand
.setSkip
(int skip) Skip the number of commits before starting to show the commit output.Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
Field Details
-
walk
-
startSpecified
private boolean startSpecified -
revFilter
-
pathFilters
-
excludeTreeFilters
-
maxCount
private int maxCount -
skip
private int skip
-
-
Constructor Details
-
LogCommand
Constructor for LogCommand.- Parameters:
repo
- theRepository
-
-
Method Details
-
call
Execute the command
Executes the
Log
command with all the options and parameters collected by the setter methods (e.g.add(AnyObjectId)
,not(AnyObjectId)
, ..) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.- Specified by:
call
in interfaceCallable<Iterable<RevCommit>>
- Specified by:
call
in classGitCommand<Iterable<RevCommit>>
- Throws:
GitAPIException
NoHeadException
-
add
public LogCommand add(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException Mark a commit to start graph traversal from.- Parameters:
start
- the id of the commit to start from- Returns:
this
- Throws:
MissingObjectException
- the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation toRevWalk.lookupCommit(AnyObjectId)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 toRevWalk.lookupCommit(AnyObjectId)
.JGitInternalException
- a low-level exception of JGit has occurred. The original exception can be retrieved by callingThrowable.getCause()
. Expect onlyIOException's
to be wrapped. Subclasses ofIOException
(e.g.MissingObjectException
) are typically not wrapped here but thrown as original exception- See Also:
-
not
public LogCommand not(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException Same as--not start
, or^start
- Parameters:
start
- aAnyObjectId
- Returns:
this
- Throws:
MissingObjectException
- the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation toRevWalk.lookupCommit(AnyObjectId)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 toRevWalk.lookupCommit(AnyObjectId)
.JGitInternalException
- a low-level exception of JGit has occurred. The original exception can be retrieved by callingThrowable.getCause()
. Expect onlyIOException's
to be wrapped. Subclasses ofIOException
(e.g.MissingObjectException
) are typically not wrapped here but thrown as original exception
-
addRange
public LogCommand addRange(AnyObjectId since, AnyObjectId until) throws MissingObjectException, IncorrectObjectTypeException Adds the rangesince..until
- Parameters:
since
- aAnyObjectId
object.until
- aAnyObjectId
object.- Returns:
this
- Throws:
MissingObjectException
- the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation toRevWalk.lookupCommit(AnyObjectId)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 toRevWalk.lookupCommit(AnyObjectId)
.JGitInternalException
- a low-level exception of JGit has occurred. The original exception can be retrieved by callingThrowable.getCause()
. Expect onlyIOException's
to be wrapped. Subclasses ofIOException
(e.g.MissingObjectException
) are typically not wrapped here but thrown as original exception
-
all
Add all refs as commits to start the graph traversal from.- Returns:
this
- Throws:
IOException
- the references could not be accessed- See Also:
-
addPath
Show only commits that affect any of the specified paths. The path must either name a file or a directory exactly and use/
(slash) as separator. Note that regex expressions or wildcards are not supported.- Parameters:
path
- a repository-relative path (with/
as separator)- Returns:
this
-
excludePath
Show all commits that are not within any of the specified paths. The path must either name a file or a directory exactly and use/
(slash) as separator. Note that regular expressions or wildcards are not yet supported. If a path is both added and excluded from the search, then the exclusion wins.- Parameters:
path
- a repository-relative path (with/
as separator)- Returns:
this
- Since:
- 5.6
-
setSkip
Skip the number of commits before starting to show the commit output.- Parameters:
skip
- the number of commits to skip- Returns:
this
-
setMaxCount
Limit the number of commits to output.- Parameters:
maxCount
- the limit- Returns:
this
-
add
private LogCommand add(boolean include, AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException, JGitInternalException -
setRevFilter
Set a filter for theLogCommand
.- Parameters:
aFilter
- the filter that this instance ofLogCommand
should use- Returns:
this
- Since:
- 4.4
-