0

我正在尝试从 SVNKit 文档中的文档中编写/改编的方法,但无济于事。如果文件与特定修订版匹配,我正在尝试打印出文件的内容。问题是我不确定如何正确使用 getfile 调用。我只是不确定我需要传递给它的字符串。任何帮助将不胜感激!!

 public static void listEntries(SVNRepository repository, String path, int revision, List<S_File> file_list) throws SVNException {
      Collection entries = repository.getDir(path, revision, null, (Collection) null);
      Iterator iterator = entries.iterator();
      while (iterator.hasNext()) {
           SVNDirEntry entry = (SVNDirEntry) iterator.next();

           if (entry.getRevision() == revision) {
                SVNProperties fileProperties = new SVNProperties();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                S_File toadd = new S_File(entry.getDate(), entry.getName(), entry.getRevision());                


                try {                        
                    SVNNodeKind nodeKind = repository.checkPath(path + entry.getName(), revision); //**PROBLEM HERE**

                    if (nodeKind == SVNNodeKind.NONE) {
                        System.err.println("There is no entry there");
                        //System.exit(1);
                    } else if (nodeKind == SVNNodeKind.DIR) {
                        System.err.println("The entry is a directory while a file was expected.");
                        //System.exit(1);
                    }                        
                    repository.getFile(path + entry.getName( ), revision, fileProperties, baos);


                } catch (SVNException svne) {
                    System.err.println("error while fetching the file contents and properties: " + svne.getMessage());
                    //System.exit(1);
                }
4

1 回答 1

1

问题可能与早期版本中的路径不同有关,例如 /Repo/components/new/file1.txt [rev 1002] 可能已从 /Repo/components/old/file1.txt [rev 1001] 移出. 尝试在路径 /Repo/components/new/ 处获取修订版 1001 的 file1.txt 将引发 SVNException。

SVNRepository 类有一个getFileRevisions方法,该方法返回一个 Collection,其中每个条目都有一个给定修订号的路径,因此可以将该路径传递给 getFile 方法:

String inintPath = "new/file1.txt";
Collection revisions = repo.getFileRevisions(initPath, 
                       null, 0, repo.getLatestRevision());
Iterator iter = revisions.iterator();
while(iter.hasNext())
{
SVNFileRevision rv = (SVNFileRevision) iter.next();

InputStream rtnStream = new ByteArrayInputStream("".getBytes());
    SVNProperties fileProperties = new SVNProperties();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    repo.getFile(rv.getPath(), rv.getRevision(), fileProperties, baos); 
}
于 2012-08-31T15:59:42.923 回答