public class LogCommand extends GitCommand<Iterable<RevCommit>>
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();
repo
Modifier | Constructor and Description |
---|---|
protected |
LogCommand(Repository repo)
Constructor for LogCommand.
|
Modifier and Type | Method and 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 range
since..until |
LogCommand |
all()
Add all refs as commits to start the graph traversal from.
|
Iterable<RevCommit> |
call() |
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 the
LogCommand . |
LogCommand |
setSkip(int skip)
Skip the number of commits before starting to show the commit output.
|
checkCallable, getRepository, setCallable
protected LogCommand(Repository repo)
repo
- the Repository
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.
call
in interface Callable<Iterable<RevCommit>>
call
in class GitCommand<Iterable<RevCommit>>
GitAPIException
NoHeadException
public LogCommand add(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException
start
- the id of the commit to start fromthis
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 to
RevWalk.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 to
RevWalk.lookupCommit(AnyObjectId)
.JGitInternalException
- a low-level exception of JGit has occurred. The original
exception can be retrieved by calling
Throwable.getCause()
. Expect only
IOException's
to be wrapped. Subclasses of
IOException
(e.g.
MissingObjectException
) are
typically not wrapped here but thrown as original exceptionRevWalk.markStart(RevCommit)
public LogCommand not(AnyObjectId start) throws MissingObjectException, IncorrectObjectTypeException
--not start
, or ^start
start
- a AnyObjectId
this
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 to
RevWalk.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 to
RevWalk.lookupCommit(AnyObjectId)
.JGitInternalException
- a low-level exception of JGit has occurred. The original
exception can be retrieved by calling
Throwable.getCause()
. Expect only
IOException's
to be wrapped. Subclasses of
IOException
(e.g.
MissingObjectException
) are
typically not wrapped here but thrown as original exceptionpublic LogCommand addRange(AnyObjectId since, AnyObjectId until) throws MissingObjectException, IncorrectObjectTypeException
since..until
since
- a AnyObjectId
object.until
- a AnyObjectId
object.this
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 to
RevWalk.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 to
RevWalk.lookupCommit(AnyObjectId)
.JGitInternalException
- a low-level exception of JGit has occurred. The original
exception can be retrieved by calling
Throwable.getCause()
. Expect only
IOException's
to be wrapped. Subclasses of
IOException
(e.g.
MissingObjectException
) are
typically not wrapped here but thrown as original exceptionpublic LogCommand all() throws IOException
this
IOException
- the references could not be accessedadd(AnyObjectId)
public LogCommand addPath(String path)
/
(slash)
as separator. Note that regex expressions or wildcards are not supported.path
- a repository-relative path (with /
as separator)this
public LogCommand setSkip(int skip)
skip
- the number of commits to skipthis
public LogCommand setMaxCount(int maxCount)
maxCount
- the limitthis
public LogCommand setRevFilter(RevFilter aFilter)
LogCommand
.aFilter
- the filter that this instance of LogCommand
should usethis
Copyright © 2019 Eclipse JGit Project. All rights reserved.