我正在尝试从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);
}
答案 0 :(得分: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);
}