我正在使用JGit提供一个服务,该服务将提供有关各种远程存储库的信息。我正在尝试使用JGit的LogCommand来完成这个任务,但是我一直无法找到这样的方法。
我试图实现以下类似的目标:
git log --author="<username>" --pretty=tformat: --shortstat但是,我找不到任何这样的功能。有没有一种方法,我可以这样做,使用或不使用JGit?
发布于 2015-06-26 07:20:20
与本机Git的log命令相比,LogCommand if JGit只提供基本选项。但是JGit中有一个JGit,它允许在迭代提交时指定自定义过滤器。
例如:
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();只包含“author”提交的示例RevFilter可能如下所示:
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
}
};若要中止步行,筛选器可能抛出一个StopWalkException。
https://stackoverflow.com/questions/31060706
复制相似问题