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?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Himself12794
  • 251
  • 3
  • 13
  • 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. – Rüdiger Herrmann Jun 26 '15 at 10:28

1 Answers1

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.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • looks good, but is there a way to get the lines of revisions/deletions? – Himself12794 Jun 26 '15 at 13:07
  • How to list the changes between two commits, see [this post](http://stackoverflow.com/questions/27361538/jgit-show-changes-between-commits) and [this post](http://stackoverflow.com/questions/28785364/jgit-list-of-files-changed-between-commits) – Rüdiger Herrmann Jun 26 '15 at 14:43