Differences between revisions 6 and 7
Revision 6 as of 2008-09-05 18:15:57
Size: 2204
Editor: 194
Comment:
Revision 7 as of 2008-09-05 18:33:45
Size: 3253
Editor: 194
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= SVNRepository.getStatus() vs. SVNRepository.getDir() = = SVNRepository.status() vs. SVNRepository.getDir() =
Line 28: Line 28:
Status is an update-like operation, it follows the same concepts described in Status is an update-like operation, it follows the same concepts described in [[Describing a local tree to the server]], but in contrast to ''update()'' status operation
does not request file deltas what results in much lesser amount of data passed over the network. As in a basic update operation you have to report to the server what you already have locally. In this case saying that we are 'still emtpy' will do:

{{{#!java
            final long rev = repos.getLatestRevision();

            ISVNReporterBaton reporter = new ISVNReporterBaton() {
                public void report(ISVNReporter reporter) throws SVNException {
                    reporter.setPath("", null, rev, SVNDepth.INFINITY,
                            true/*we are empty, take us all like in checkout*/);
                    reporter.finishReport();
                }
            };
}}}

Paths reported by [[ISVNReporterBaton]] are relative to the location of [[SVNRepository]]. In the previous code snippet we say that we would like the server to send us all paths under the location of our [[SVNRepository]] accessor recursively.

SVNRepository.status() vs. SVNRepository.getDir()

Here we will show how you can fetch properties from the repository recursively in a single request using SVNRepository. Many newbie users who come across the SVNRepository interface for the first time, decide to implement the task of recursive retrieving properties from a repository tree with the help of SVNRepository's getDir() method. To get properties recursively you'll have to call getDir() in recursion. It's not a wrong way, but consider the repository tree with multiple leaves (with hundreds or maybe thousands of them). For each directory leave getDir() sends a new request what leads to extremely slow performance.

Basically, what you do with getDir() is the following:

   1     public void fetchPropsFromRepository(SVNRepository repos, String path, long revision, 
   2                                          Map pathsToProps) throws SVNException {
   3         SVNProperties props = new SVNProperties();
   4         Collection children = repos.getDir(path, revision, props, SVNDirEntry.DIRENT_ALL, null);
   5         pathsToProps.put(path, props);
   6         for (Iterator childrenIter = children.iterator(); childrenIter.hasNext();) {
   7             SVNDirEntry childEntry = (SVNDirEntry) childrenIter.next();
   8             if (childEntry.getKind() == SVNNodeKind.DIR) {
   9                 String childName = childEntry.getName();
  10                 String childPath = !"".equals(path) && !path.endsWith("/") ? 
  11                                    path + "/" + childName : path + childName;
  12                 fetchPropsFromRepository(repos, childPath, revision, pathsToProps);
  13             }
  14         }    
  15     }

So, you simply call getDir() recursively storing properties on the way. But as it has already been mentioned, each call to getDir() results in one more request to the server. Instead you may use SVNRepository's status() method to fetch all the properties with the following benefits:

  • you make only one single request to the server what gives lesser network overhead
  • no recursion at all

Status is an update-like operation, it follows the same concepts described in Describing a local tree to the server, but in contrast to update() status operation does not request file deltas what results in much lesser amount of data passed over the network. As in a basic update operation you have to report to the server what you already have locally. In this case saying that we are 'still emtpy' will do:

   1             final long rev = repos.getLatestRevision(); 
   2 
   3             ISVNReporterBaton reporter = new ISVNReporterBaton() {
   4                 public void report(ISVNReporter reporter) throws SVNException {
   5                     reporter.setPath("", null, rev, SVNDepth.INFINITY, 
   6                             true/*we are empty, take us all like in checkout*/);
   7                     reporter.finishReport();
   8                 }
   9             }; 

Paths reported by ISVNReporterBaton are relative to the location of SVNRepository. In the previous code snippet we say that we would like the server to send us all paths under the location of our SVNRepository accessor recursively.

Recursively fetching properties from a repository (low-level API) (last edited 2008-09-05 18:59:11 by 194)