Compared with native Git's log
command, the LogCommand
if JGit offers only basic options. But there is a RevWalk
in JGit that allows to specify custom filters while iterating over commits.
For example:
RevWalk walk = new RevWalk( repo );
walk.markStart( walk.parseCommit( repo.resolve( Constants.HEAD ) ) );
walk.sort( RevSort.REVERSE ); // chronological order
walk.setRevFilter( myFilter );
for( RevCommit commit : walk ) {
// print commit
}
walk.close();
An example RevFilter
that includes only commits of 'author' could look like this:
RevFilter filter = new RevFilter() {
@Override
public boolean include( RevWalk walker, RevCommit commit )
throws StopWalkException, IOException
{
return commit.getAuthorIdent().getName().equals( "author" );
}
@Override
public RevFilter clone() {
return this; // may return this, or a copy if filter is not immutable
}
};
To abort the walk, a filter may throws a StopWalkException
.