2012-04-17 44 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); 
} 
相關問題