Accessing the SVN log from java Code

461 views
Skip to first unread message

Arijit Datta

unread,
Apr 17, 2012, 2:53:30 PM4/17/12
to us...@subversion.apache.org
Hello,

We have a requirement whereby we need to access a svn server and find the no. of check-ins happening for each repository.

For example the SVN is hosted at https://svnexample.net

And there are 3 repositories on it:

https://svnexample.net/rep/project1
https://svnexample.net/rep/project2
https://svnexample.net/rep/project3

The requirement is to connect to this server and then find out the number of check-in / check-outs happening per project. We want to build a web application which does that and gives the user the data in form of graphs, etc.

How do we go about doing that? That is how do we access the svn server from inside the java code and get these details?

Thanks
AJ

Rob van Oostrum

unread,
Apr 17, 2012, 3:12:49 PM4/17/12
to us...@subversion.apache.org
http://svnkit.com/ would be an obvious place to start.

Andy Levy

unread,
Apr 17, 2012, 3:15:41 PM4/17/12
to Arijit Datta, us...@subversion.apache.org

The repository doesn't keep track of checkouts, so you cannot glean
that data from the repository. Ryan Schmidt has a script that can be
used to parse Apache logs to collect this information.

I would recommend against pulling this data from the log in realtime,
but instead populate a database with the relevant data (you'll have to
write something to do this for an initial population of the database
using a one-time output of svn log, then have a post-commit hook which
updates the database going forward), and generate your reports from
queries against that database. The only instance where this would
become a problem is if you regularly change revision properties, but
you can have a post-revprop-change hook to perform those updates if
needed.

Although I don't use it to retrieve/parse log entries, I use SVNKit to
interrogate my repository from within Java. http://svnkit.com/

Arijit Datta

unread,
Apr 17, 2012, 3:22:48 PM4/17/12
to Andy Levy, us...@subversion.apache.org
Hello Andy,

Thanks for the quick reply. We are also not bothered with the checkouts. We are only bothered about the check-ins & we will also have similar DB setup. But we will do a nightly refresh of the data in DB by pulling the log data from the svn repository.

However, the point of this post is the Java Code. I am not sure how I can "look up" the svn repository from the code. Was hoping if a good Samaritan would help out with a code snippet. 

Also, I am unsure who Ryan Schmidt is & how do I get in touch with him.

Thanks. 
AJ


From: Andy Levy <andy...@gmail.com>
To: Arijit Datta <arijit...@ymail.com>
Cc: "us...@subversion.apache.org" <us...@subversion.apache.org>
Sent: Wednesday, 18 April 2012 12:45 AM
Subject: Re: Accessing the SVN log from java Code

Arijit Datta

unread,
Apr 17, 2012, 3:30:53 PM4/17/12
to Andy Levy, us...@subversion.apache.org
Hello Andy,

I am not sure if I understand this:

"The only instance where this would
become a problem is if you regularly change revision properties, but
you can have a post-revprop-change hook to perform those updates if
needed."

Could you kindly explain.

Thanks,
AJ


From: Andy Levy <andy...@gmail.com>
To: Arijit Datta <arijit...@ymail.com>
Cc: "us...@subversion.apache.org" <us...@subversion.apache.org>
Sent: Wednesday, 18 April 2012 12:45 AM
Subject: Re: Accessing the SVN log from java Code

Andy Levy

unread,
Apr 17, 2012, 3:40:39 PM4/17/12
to Arijit Datta, us...@subversion.apache.org
On Tue, Apr 17, 2012 at 15:30, Arijit Datta <arijit...@ymail.com> wrote:
> Hello Andy,
>
> I am not sure if I understand this:
>
> "The only instance where this would
> become a problem is if you regularly change revision properties, but
> you can have a post-revprop-change hook to perform those updates if
> needed."
>
> Could you kindly explain.

The contents of every commit are immutable, but the revision
properties (user ID, timestamp, log message) can be changed if the
repository is configured to allow it (by not rejecting the action in
the pre-revprop-change hook script). If your repository is configured
in this way, you can write a post-revprop-change hook script which
would update the corresponding record in your database to capture the
change, without having to reload all the data in the database.

jose.nun...@barclays.com

unread,
Apr 17, 2012, 3:46:12 PM4/17/12
to arijit...@ymail.com, andy...@gmail.com, us...@subversion.apache.org

Hi,

 

You definitely NEED to read the documentation, here are some pointers so you can get started:

 

·         Several examples: http://wiki.svnkit.com/Managing_Repository_With_SVNKit

·         WIKI API: http://svnkit.com/kb/javadoc/org/tmatesoft/svn/core/wc/package-summary.html (API)

 

But basically it drills down to (Jython code showed, Java is VERY similar):

 

from org.tmatesoft.svn.core import *

from org.tmatesoft.svn.core.io import SVNRepositoryFactory

from org.tmatesoft.svn.core.internal.io.svn import SVNRepositoryFactoryImpl

from org.tmatesoft.svn.core.internal.io.dav import DAVRepositoryFactory

from org.tmatesoft.svn.core.auth import BasicAuthenticationManager

from org.tmatesoft.svn.core.wc import SVNClientManager

from org.tmatesoft.svn.core.wc import SVNRevision

 

SVNRepositoryFactoryImpl.setup()

DAVRepositoryFactory.setup()

durl = SVNURL.parseURIDecoded(url) // Where URL is your SVN url, that starts with http:// blah, blah

repository = SVNRepositoryFactory.create(durl)

authManager = BasicAuthenticationManager(svnuser, svnpassword)

repository.setAuthenticationManager(authManager)

myOptions = None

clientManager = SVNClientManager.newInstance(myOptions, authManager)

updateClient = clientManager.getUpdateClient()

updateClient.setIgnoreExternals(False)

dstPath = File(sandbox)

rev = updateClient.doCheckout(desturl.appendPath("/trunk", False), dstPath, SVNRevision.HEAD, SVNRevision.HEAD, True)

 

Regards,

 

--Jose

_______________________________________________

Barclays is one of the world's leading banks, and we believe that by continuing to integrate the organisation we can better deliver the full power of Barclays to customers, clients and the communities in which we work.

As a visible sign of that integration we are moving to a single Barclays brand for the majority of our divisions, including those formerly known as Barclays Capital, Barclays Wealth and Barclays Corporate.

_______________________________________________

This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing.  Barclays offers premier investment banking products and services to its clients through Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP.  This email may relate to or be sent from other members of the Barclays Group.

_______________________________________________

Ryan Schmidt

unread,
Apr 18, 2012, 12:11:13 AM4/18/12
to Arijit Datta, Andy Levy, us...@subversion.apache.org
On Apr 17, 2012, at 14:22, Arijit Datta wrote:
> Andy Levy wrote:

>> On Tue, Apr 17, 2012 at 14:53, Arijit Datta wrote:
>>> We have a requirement whereby we need to access a svn server and find the
>>> no. of check-ins happening for each repository.

>> The repository doesn't keep track of checkouts, so you cannot glean


>> that data from the repository. Ryan Schmidt has a script that can be
>> used to parse Apache logs to collect this information.

> Also, I am unsure who Ryan Schmidt is & how do I get in touch with him.

I am here; I read the list.

The script Andy is referring to is:

http://www.ryandesign.com/svnhookdispatcher/

I assume it still works, though I haven't looked at it in years.

Reply all
Reply to author
Forward
0 new messages