[英]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.