Reputation: 933
I'm trying to get a method that I wrote/adapted from the documentation from the SVNKit documentation working but to no avail. I'm trying to print out the contents of a file if it matches a particular revision. The problem is that I'm not sure how to properly use the getfile call. I'm just not sure of the strings that I need to pass to it. Any help would be greatly appreciated!!
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);
}
Upvotes: 0
Views: 1018
Reputation: 656
The problem may be related to the path in earlier revisions being different, for example a /Repo/components/new/file1.txt [rev 1002] may have been moved from /Repo/components/old/file1.txt [rev 1001]. Trying to get the file1.txt with revision 1001 at path /Repo/components/new/ will throw an SVNException.
SVNRepository class has a getFileRevisions method that returns a Collection where each entry has a path for a given revision number so it is this path that could be passed to the getFile method:
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);
}
Upvotes: 1