Filter JGit-获取影响文件/路径的所有提交(PlotCommitList)
为什么我要尝试获取包括我的存储库的特定目录或文件的所有提交 我尝试了以下代码:Filter JGit-获取影响文件/路径的所有提交(PlotCommitList),filter,path,commit,jgit,Filter,Path,Commit,Jgit,为什么我要尝试获取包括我的存储库的特定目录或文件的所有提交 我尝试了以下代码: public PlotCommitList getPlotCommits(String path){ System.out.println(path); PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>(); PlotWalk revWalk = new PlotWalk(rep
public PlotCommitList getPlotCommits(String path){
System.out.println(path);
PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
PlotWalk revWalk = new PlotWalk(repository);
try {
ObjectId rootId = repository.resolve("HEAD");
if (rootId != null) {
RevCommit root = revWalk.parseCommit(rootId);
revWalk.markStart(root);
revWalk.setTreeFilter(PathFilter.create(path));
plotCommitList.source(revWalk);
plotCommitList.fillTo(Integer.MAX_VALUE);
return plotCommitList;
}
} catch (AmbiguousObjectException ex) {
Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE, null, ex);
}
return plotCommitList;
}
public PlotCommitList getPlotCommits(字符串路径){
System.out.println(路径);
PlotCommitList PlotCommitList=新建PlotCommitList();
PlotWalk revWalk=新建PlotWalk(存储库);
试一试{
ObjectId rootId=repository.resolve(“HEAD”);
if(rootId!=null){
RevCommit root=revWalk.parseCommit(rootId);
revWalk.markStart(根);
revWalk.setTreeFilter(PathFilter.create(path));
plotCommitList.source(revWalk);
plotCommitList.fillTo(整数.MAX_值);
返回plotCommitList;
}
}捕获(模糊ObjectException ex){
Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE,null,ex);
}捕获(IOEX异常){
Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE,null,ex);
}
返回plotCommitList;
}
我不仅仅得到影响该文件的提交。我得到了整个列表的一些“子列表”,但不仅仅是那些影响该文件的提交
也许TreeFilter不起作用我怎么想的?我应该用其他方法来获得这些承诺?
我看到log命令有一个路径过滤器,但我还没有尝试,因为它返回一个RevCommit列表,对于我的PlotCommitList,我需要一个revwalk作为源。而且我认为我不能将RevCommit转换为PlotCommit
一个家伙在这里遇到了同样的问题(第一个答案是fileA和fileB问题):您需要将
路径过滤器
与任何不同的过滤器结合起来:
revWalk.setTreeFilter(
AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF));
仅使用PathFilter,我认为发生的情况是,在指定树存在的位置选择所有提交(例如,从该文件的初始提交开始的所有提交)
另请参见或如何操作。您需要将路径过滤器
与任何不同的过滤器结合使用:
revWalk.setTreeFilter(
AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF));
仅使用PathFilter,我认为发生的情况是,在指定树存在的位置选择所有提交(例如,从该文件的初始提交开始的所有提交)
还可以看看或是怎么做的。它就像一个符咒,我真是个笨蛋!这是如此简单,也记录在案。谢谢你的提示。它很有魅力,我真是个笨蛋!这是如此简单,也记录在案。谢谢你的提示。