Question

I am currently trying to get all SVN Revisions and afterwards check them out one after another and do something with them.

With

svn checkout http://hamcrest.googlecode.com/svn/trunk/ hamcrest-read-only

(using SVN 1.8.8) I get the code (I am just using hamcrest as an example).

After getting it, I am trying to do the following:

    FSRepositoryFactory.setup();
    SVNURL localRepo = FSRepositoryFactory.createLocalRepository(f, true,
            true);
    System.out.println("Repo: " + localRepo);
    SVNRepository repo = FSRepositoryFactory.create(localRepo);

    log.info("Revisions: " + repo.getLatestRevision() + " Path: "
            + f.getAbsolutePath());
    List<SVNLogEntry> col = (List<SVNLogEntry>) repo.log(
            new String[] { "" }, null, 0, repo.getLatestRevision(), true,
            true);

    for (Object o : col) {
        System.out.println("O: " + o + " " + o.getClass());
    }

    System.out.println("Col: " + col.getClass());

This unfortunately creates an empty repository, and deletes everything in it. This corresponds to the documentation of FSRepositoryFactory.create.

So I searched for an way to open an existing repository another way, and found SVNURL localRepo = SVNURL.fromFile(f);. Unfortunately, this produces the errors:

Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn: E180001: Unable to open an ra_local session to URL
svn: E180001: Unable to open repository 'file:///home/reichelt/workspace/hamcrest/hamcrest-read-only'
svn: E180001: Unable to open repository 'file:///home/reichelt/workspace/hamcrest/hamcrest-read-only'
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
at org.tmatesoft.svn.core.internal.io.fs.FSRepository.openRepository(FSRepository.java:796)
at org.tmatesoft.svn.core.internal.io.fs.FSRepository.getLatestRevision(FSRepository.java:121)
at de.performanzanalysator.vcs.SVNUtils.getVersions(SVNUtils.java:70)
at de.performanzanalysator.vcs.SVNUtils.main(SVNUtils.java:90)

Does anyone know weather there is a way to open an existing, already downloaded repository with SVNKit? The SVNWCClient seems right, but I can't find any method to open a repository with SVNWCClient.

I am using SVNKit 1.8.5.

Was it helpful?

Solution

The exception mentioned in the questions happens because the SVNRepository class expects to be used against a repository but it is used against a working copy.

The server-side part of the SVN is called repository and the client-side part is called working copy. The svn checkout command is used the create a (usually local) working copy from a (usually remote) repository. The working copy contains a single revision only, and because of that some operations (log, for example) will need access to the remote repository.

The SvnOperationFactory class provides an API to perform all "generic" SVN tasks both against working copies and repositories. It can be used to get the full change log but remember that it will contact the repository even if the log operation is initiated against the local working copy.

File workingCopyLocation = new File( ... );

SvnOperationFactory operationFactory = new SvnOperationFactory();
SvnLog logOperation = operationFactory.createLog();
logOperation.setSingleTarget(
        SvnTarget.fromFile( workingCopyLocation )
);
logOperation.setRevisionRanges( Collections.singleton(
        SvnRevisionRange.create(
                SVNRevision.create( 1 ),
                SVNRevision.HEAD
        )
) );
Collection<SVNLogEntry> logEntries = logOperation.run( null );
System.out.println( "logEntries = " + logEntries );

You can use the same code to obtain the change log directly from the repository without checking out the working copy by changing the setSingleTarget initialization to point to the remote repository:

String repoLocation = "http://hamcrest.googlecode.com/svn/trunk";
logOperation.setSingleTarget(
        SvnTarget.fromURL(
                SVNURL.parseURIEncoded( repoLocation )
        )
);

Since SVNKit 1.7 the SvnOperationFactory is the preferred way of using SVNKit. The SVNKit still contains SVNClientManager which provides similar capabilities but it is considered obsolete.

The SVNRepository class and its subclasses are intended to interact with repositories, which is useful if you are writing software that creates, configures or serves SVN repositories. For example, you can use that API to get the change log directly from the repository but unless you are writing some server-side software that performs other repository-related tasks you should use SvnOperationFactory approach.

String repoLocation = "http://hamcrest.googlecode.com/svn/trunk";

// DAV allows access via http and https protocols
// use FSRepositoryFactory to access local repositories
// use SVNRepositoryFactory to access remote repositories via svn protocol
DAVRepositoryFactory.setup();
SVNRepository repository = DAVRepositoryFactory.create(
        SVNURL.parseURIEncoded( repoLocation )
);

repository.log(
        new String[]{ },
        0, -1,
        false, false,
        new ISVNLogEntryHandler()
        {
            @Override
            public void handleLogEntry( SVNLogEntry logEntry )
            {
                System.out.println( "logEntry = " + logEntry );
            }
        }
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top