1

Is there any way to get the SVN structure as a tree struture in java?

For Eg: if i specify a path http://sample.com/repository/pag/branches/dev/Structure/services/

I want what all entries under services and if it again contains a directory its enteries also in a tree?

Thanks.

Note : i have seen the getDir(). But here i have to keep on iterating it.

2
  • 1
    What's the problem with iterating yourself and building the tree yourself? Commented Jul 11, 2012 at 11:02
  • wen ever i give getDir() it is taking 5 to 10 secs to give output... I have 10 nested directories under '/service'. Thats why i'm thinking Commented Jul 11, 2012 at 11:11

1 Answer 1

4

If you need all the tree, you may do that with "status" request with report telling that you have an empty working copy. One "status" request should be faster than a number of getDir() requests. An example how to do that with SVNKit

   final SVNRepository svnRepository = SVNRepositoryFactory.create(url);
    try {
        svnRepository.status(revision, "", SVNDepth.INFINITY, new ISVNReporterBaton() {
            @Override
            public void report(ISVNReporter reporter) throws SVNException {
                reporter.setPath("", null, revision, SVNDepth.INFINITY, true);
                reporter.finishReport();
            }
        }, new ISVNEditor() {
            @Override
            public void targetRevision(long revision) throws SVNException {

            }

            @Override
            public void openRoot(long revision) throws SVNException {
                System.out.println("<root>");
            }

            @Override
            public void deleteEntry(String path, long revision) throws SVNException {
            }

            @Override
            public void absentDir(String path) throws SVNException {
            }

            @Override
            public void absentFile(String path) throws SVNException {
            }

            @Override
            public void addDir(String path, String copyFromPath, long copyFromRevision) throws SVNException {
                System.out.println("directory: " + path);
            }

            @Override
            public void openDir(String path, long revision) throws SVNException {
            }

            @Override
            public void changeDirProperty(String name, SVNPropertyValue value) throws SVNException {
            }

            @Override
            public void closeDir() throws SVNException {
            }

            @Override
            public void addFile(String path, String copyFromPath, long copyFromRevision) throws SVNException {
                System.out.println("file: " + path);
            }

            @Override
            public void openFile(String path, long revision) throws SVNException {
            }

            @Override
            public void changeFileProperty(String path, String propertyName, SVNPropertyValue propertyValue) throws SVNException {
            }

            @Override
            public void closeFile(String path, String textChecksum) throws SVNException {
            }

            @Override
            public SVNCommitInfo closeEdit() throws SVNException {
                return null;
            }

            @Override
            public void abortEdit() throws SVNException {
            }

            @Override
            public void applyTextDelta(String path, String baseChecksum) throws SVNException {
            }

            @Override
            public OutputStream textDeltaChunk(String path, SVNDiffWindow diffWindow) throws SVNException {
                return null;
            }

            @Override
            public void textDeltaEnd(String path) throws SVNException {
            }
        });
    } finally {
        svnRepository.closeSession();
    }
Sign up to request clarification or add additional context in comments.

4 Comments

Hi thanks for ur reply... If i have a large directory system will this be good?
Yes, this is the best approach if you want to visit everything in some "url" at some "revision" (you can specify an url of subdirectory if you don't want to start at the root). Especially it is good if the directory system is large. The only case when this approach is not good --- if you want to crawl all directories to some certain depth (say, 5) or if the depth depends on the directories contents --- then use getDir().
If the depth is also large.. say size-2 . i can use this rite?
I think, yes, if size is large enough. It's simple just to measure. Theoretically, if you work over network, for the "status" request, you'll get a long XML response with editor calls (you may turn SVNKit logging on to see what is sent on the server), but it will be only one request. But every getDir() call will be a separate request that should take much more time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.