Package org.eclipse.jgit.api
Class LogCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<Iterable<RevCommit>>
-
- org.eclipse.jgit.api.LogCommand
-
public class LogCommand extends GitCommand<Iterable<RevCommit>>
A class used to execute aLog
command. It has setters for all supported options and arguments of this command and acall()
method to finally execute the command. Each instance of this class should only be used for one invocation of the command (means: one call tocall()
)Examples (
git
is aGit
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:
- Git documentation about Log
-
-
Field Summary
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LogCommand(Repository repo)
Constructor for LogCommand.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LogCommand
add(AnyObjectId start)
Mark a commit to start graph traversal from.LogCommand
addPath(String path)
Show only commits that affect any of the specified paths.LogCommand
addRange(AnyObjectId since, AnyObjectId until)
Adds the rangesince..until
LogCommand
all()
Add all refs as commits to start the graph traversal from.Iterable<RevCommit>
call()
LogCommand
excludePath(String path)
Show all commits that are not within any of the specified paths.LogCommand
not(AnyObjectId start)
Same as--not start
, or^start
LogCommand
setMaxCount(int maxCount)
Limit the number of commits to output.LogCommand
setRevFilter(RevFilter aFilter)
Set a filter for theLogCommand
.LogCommand
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
-
-
-
-
Constructor Detail
-
LogCommand
protected LogCommand(Repository repo)
Constructor for LogCommand.- Parameters:
repo
- theRepository
-
-
Method Detail
-
call
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException
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:
RevWalk.markStart(RevCommit)
-
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
public LogCommand all() throws IOException
Add all refs as commits to start the graph traversal from.- Returns:
this
- Throws:
IOException
- the references could not be accessed- See Also:
add(AnyObjectId)
-
addPath
public LogCommand addPath(String path)
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
public LogCommand excludePath(String path)
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
public LogCommand setSkip(int skip)
Skip the number of commits before starting to show the commit output.- Parameters:
skip
- the number of commits to skip- Returns:
this
-
setMaxCount
public LogCommand setMaxCount(int maxCount)
Limit the number of commits to output.- Parameters:
maxCount
- the limit- Returns:
this
-
setRevFilter
public LogCommand setRevFilter(RevFilter aFilter)
Set a filter for theLogCommand
.- Parameters:
aFilter
- the filter that this instance ofLogCommand
should use- Returns:
this
- Since:
- 4.4
-
-