1

リポジトリの特定のディレクトリまたはファイルを含むすべてのコミットを取得しようとしています。

私は次のコードを試しました:

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;
}

そのファイルに影響を与えたコミットだけを取得するわけではありません。リスト全体のいくつかの「サブリスト」を取得しますが、そのファイルに影響を与えたコミットだけではありません。

たぶんTreeFilterは私の考えでは機能しませんか?これらのコミットを取得するには、他の方法を使用する必要がありますか?logコマンドにパスフィルターがあるのを見ましたが、RevCommitリストが返され、PlotCommitListの場合は、ソースとして使用するrevwalkが必要なため、まだ試していません。また、RevCommitをPlotCommitにキャストできないと思います。

男はここで同じ問題を抱えていました(fileAとfileBの問題に関する最初の回答):リンク-ここをクリックしてください

4

1 に答える 1

5

PathFilterANY_DIFFフィルターと組み合わせる必要があります。

revWalk.setTreeFilter(
    AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF));

PathFilterだけを使用すると、指定されたツリーが存在する場所ですべてのコミットが選択されると思います(たとえば、そのファイルの最初のコミットから始まるすべてのコミット)。

setTreeFilterのAPIドキュメントまたはLogCommandがそれを行う方法も参照してください。

于 2012-10-02T19:58:39.650 に答える