1

I'm using JGit to provide a service that will give information about various remote repositories. I'm trying to use JGit's LogCommand to do this, however I have been unable to find a way to do this.

I'm trying to achieve something analogous to doing the following:

git log --author="<username>" --pretty=tformat: --shortstat

However, I can't find any functionality that does that. Is there a way I could do this, with or without JGit?

1
  • I see you're new to SO. If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. This helps keep the focus on older posts which still don't have answers. Commented Jun 26, 2015 at 10:28

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

looks good, but is there a way to get the lines of revisions/deletions?
How to list the changes between two commits, see this post and this post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.