Search code examples
svnkit

Get only X latest log items from SVNKit


I want to know the last revisions of a SVN Tag. In my case, not the actual one, but one before (or said differently, the revision from which the repository was tagged from).

I have this code that gets me what I want:

        Collection<SVNLogEntry> log = repository.log(new String[]{""}, null, 1, -1, false, false);
        List<Long> revisions = log.stream().map(entry -> entry.getRevision()).sorted().collect(Collectors.toList());
        System.out.println("Wanted Revision:" + revisions.get(revisions.size()-2));

However, with a big SVN Repository it is just too slow as I get alot of revisions I don't need. I can hardly set the startRevision because I have no info on where to get it from (programatically)...

I would be happy if I could get the X newest elements from the log, this way it would perform well and I could get the info I need, but I find no way to do such a thing, even though Eclipse does limit History even using SVNKit, so it must be possible to get the last N revisions without explicitly setting a startRevision.

What's the big secret I'm not understanding about the SVNKit API?

I have the following import:

compile group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.8.12'

UPDATE:

I tried following approach:

        repository.log(new String[]{""}, 1, -1, false, false, 15 /* limit */, false, null,
            new ISVNLogEntryHandler()
            {
                @Override
                public void handleLogEntry(SVNLogEntry logEntry) throws SVNException
                {
                    logs.add(logEntry);
                }
            });

However, this does the filtering in Java (could also be expressed as a lambda), not from the repository, so it performs just the same as the sample above, plus it shows the first 15 results, not the last ones...


Solution

  • I am thinking there is no clean solution to this problem (though I do not know the SVN internals)...

    What I found out that will work is the following:

            SVNDirEntry info = repository.info("", -1);
            Collection<SVNLogEntry> log = repository.log(new String[]{""}, null, info.getRevision() - 500, -1, false, false);
            List<Long> revisions = log.stream().map(entry -> entry.getRevision()).sorted().collect(Collectors.toList());
            revision = revisions.get(revisions.size()-2);
    

    This way it will not retrieve so many results (only the last 500 revisions). For my example maybe a -10 or -50 would do it, but I want to be sure... Will still refactor it to be sure that if info.getRevision is < 500 it will take 1.

    I am still not happy with this because I should be validating the size of the log, and if <2 get another 500, but I will live with this potential bug right now (it's a tool for my usage, not something I will deploy)... Dealing with such things is just too much coding for the purpose...