2011-06-18 3 views
0

jitを使ってgitリポジトリブラウザを作成したいと思います。しかし、私はファイルの最終更新日と最後のコミットメッセージを取得する方法がわかりません。ここに私のブラウザのための私のコードはあります:jgitリポジトリブラウザ

File directory = new File("/Users/sdorra/.scm/repositories/git/scm-git"); 
Repository repository = 
    RepositoryCache.open(RepositoryCache.FileKey.lenient(directory, 
    FS.DETECTED), true); 

try 
{ 
    ObjectId revId = repository.resolve(Constants.HEAD); 
    DirCache cache = new DirCache(directory, FS.DETECTED); 
    TreeWalk treeWalk = new TreeWalk(repository); 

    treeWalk.addTree(new RevWalk(repository).parseTree(revId)); 
    treeWalk.addTree(new DirCacheIterator(cache)); 

    while (treeWalk.next()) 
    { 
    System.out.println("---------------------------"); 
    System.out.append("name: ").println(treeWalk.getNameString()); 
    System.out.append("path: ").println(treeWalk.getPathString()); 

    ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); 

    System.out.append("directory: ").println(loader.getType() 
         == Constants.OBJ_TREE); 
    System.out.append("size: ").println(loader.getSize()); 
    // ??? 
    System.out.append("last modified: ").println("???"); 
    System.out.append("message: ").println("???"); 
    } 
} 
finally 
{ 
    if (repository != null) 
    { 
    repository.close(); 
    } 
} 

ファイルの最後のコミットを得ることは可能ですか?

注:私のgitリポジトリは作業コピーのない裸のリポジトリです。

答えて

1

下位レベルのJGit APIを使用していますが、LogCommandをorg.eclipse.jgit.apiパッケージで使用してみませんか?次に、addPath(...)、call()を使用してください。

その後、指定したパスのRevCommitのリストを取得する必要があります。

関連する問題