[英]Why does this instance of getFile work with SVNKit?
我正在嘗試從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);
}
該問題可能與早期版本中的路徑不同有關,例如/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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.