2012-04-17 70 views
0

我试图得到一种方法,我写了/从SVNKit文档的文档工作,但无济于事。我试图打印出一个文件的内容,如果它匹配一个特定的修订版。问题是我不确定如何正确使用getfile调用。我只是不确定我需要传递给它的字符串。任何帮助将不胜感激!!为什么getFile的这个实例与SVNKit一起工作?

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

回答

1

该问题可能在早期版本是不同的,进行相关的路径例如/Repo/components/new/file1.txt [REV 1002]可能已经从移动/回购/组件/旧/ 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); 
} 
相关问题