gpt4 book ai didi

java - JGit - 通过 LogCommand 使用参数

转载 作者:行者123 更新时间:2023-11-30 03:22:17 27 4
gpt4 key购买 nike

我正在使用 JGit 提供一项服务,该服务将提供有关各种远程存储库的信息。我正在尝试使用 JGit 的 LogCommand 来执行此操作,但是我一直无法找到执行此操作的方法。

我正在尝试实现类似于执行以下操作的目标:

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

但是,我找不到任何可以做到这一点的功能。有没有办法可以做到这一点,无论有没有 JGit?

最佳答案

与原生 Git 的 log 命令相比,LogCommand if JGit 仅提供基本选项。但是 JGit 中有一个 RevWalk,它允许在迭代提交时指定自定义过滤器。

例如:

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();

仅包含“作者”提交的示例 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

关于java - JGit - 通过 LogCommand 使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31060706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com