2012-04-17 3 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 [об 1002], возможно, были перемещены из/Repo/компоненты/старый/file1.txt [rev 1001]. Попытка получить файл1.txt с ревизией 1001 в пути/Repo/components/new/будет вызывать исключение SVNException.

SVNRepository класс имеет getFileRevisions метод, который возвращает коллекцию, где каждый элемент имеет путь для заданного номера ревизии, так что этот путь, который может быть передан методу 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); 
} 
Смежные вопросы