XQuery/Subversion

Motivation
You want to be able to access a Subversion (SVN) repository, including checking out the repository's files directly into the eXist database and committing changed files back to the repository, using XQuery.

Method
A subversion XQuery module has been added to the bleeding edge development version of eXist 1.5. You can use it to query remote subversion servers, and even to check out a remote repository to store the repository's contents in the database. (If you do check out a repository, note that the subversion repository's files, including its many ".svn" files, will be stored directly in your database.) As of May 2011, the subversion module can perform most, but not all, common subversion functions.

Building the subversion extension
As with all eXist extensions that are not enabled by default, you need to instruct eXist's build process to include the extension.

You should first copy the file $EXIST_HOME/extensions/build.properties to a new file, called $EXIST_HOME/extensions/local.build.properties. This local file will be used by the build process, but it will be ignored by your subversion client so that you don't accidentally commit it to the eXist repository.

You should now locate the following line:

#SVN extension include.feature.svn = false

Change false to true:

include.feature.svn = true

Save the local.build.properties file. With these changes you must now rebuild (i.e. recompile) eXist so that the subversion extension is included in eXist's jar files.

Enable the subversion module in conf.xml
To ensure the module is available when you start eXist, un-comment the following lines in your $EXIST_HOME/conf.xml file

Save conf.xml. Now you can start eXist, and the subversion module will now be ready for you to use. You can build the subversion function documentation at http://localhost:8080/exist/admin/admin.xql?panel=fundocs and then accessing http://localhost:8080/exist/functions/subversion.

You should now be able to test the subversion XQuery functions. This should look very similar to the function listings on the eXist demo site here: http://demo.exist-db.org/exist/xquery/functions.xql

Current Status
Subversion repositories can be accessed over HTTP and HTTPS, both anonymously and with username/password authentication.

The following functions have been tested to work:


 * subversion:checkout($repository-uri as xs:string, $database-path as xs:string) xs:long
 * subversion:checkout($repository-uri as xs:string, $database-path as xs:string, $login as xs:string, $password as xs:string) xs:long
 * subversion:get-latest-revision-number($repository-uri as xs:string, $login as xs:string, $password as xs:string) xs:long
 * subversion:info($database-path as xs:string) element
 * subversion:list($repository-uri as xs:string) element
 * subversion:log($repository-uri as xs:string, $login as xs:string, $password as xs:string, $start-revision as xs:integer?, $end-revision as xs:integer?) element
 * subversion:status($database-path as xs:string) element
 * subversion:update($database-path as xs:string) xs:long
 * subversion:update($database-path as xs:string, $login as xs:string, $passwrod as xs:string) xs:long
 * subversion:add($database-path as xs:string) empty

The following works under some cases but has buffer errors for some sizes of commits:


 * subversion:commit($database-path as xs:string, $message as xs:string?, $login as xs:string, $password as xs:string) xs:long

The following functions are not yet confirmed to work and are still being tested:


 * subversion:clean-up($database-path as xs:string) empty
 * subversion:lock($database-path as xs:string, $message as xs:string?) empty
 * subversion:revert($database-path as xs:string) empty
 * subversion:unlock($database-path as xs:string) empty

subversion:get-latest-revision-number
The subversion:get-latest-revision-number function queries the remote SVN repository, returning the latest revision number. For example:

This query returns the following result:

14458

subversion:info
Once you have done a checkout of a resource from subversion you can query that resource locally and find out more about it.

subversion:info('/db/apps/faqs/data')

This will return:

subversion:list
The subversion:list function lists the contents of a remote repository, returning the results as an XML node:

This script will return the following result:

subversion:log
The subversion:log function queries the remote SVN repository, returning the log of changes as an XML node. For example, this query will return show the log of changes between two arbitrary revision numbers (note that substituting empty nodes for $start-revision and/or $end-revision will return a more open-ended log of revisions):

The results of this query are as follows (note that the @revtype values are 'A' for item added, 'D' for item deleted, 'M' for item modified, and 'R' for item replaced):

Getting the Last 10 Commit Messages
The log function can be combined with the get-latest-revision-number function to get the last 10 commit messages in the system.

subversion:checkout
The following example checks out eXist's "functions" app to the "/db/svn" collection:

This returns:

Revision 14457 successfully checked out to collection /db/svn

The /db/svn collection will now contain the following files:


 * .svn (collection)
 * controller.xql
 * filter.xql
 * functions.xql

subversion:add
After you have run a checkout you are now ready to do a subversion:commit or an subversion:add.

The both of these functions take a single argument which is the database collection path you want to send to your subversion server.

subversion:update
Assuming we have already checked out a repository to /db/svn, we can update the working copy to the latest revision using the subversion:update function:

This script will return the following result:

Successfully updated to revision 14457

You can also get updates from a secure site by using subversion:update($working-copy, $user, $password)

subversion:status
The subversion:status function returns the status of files in the local working copy. For example, assuming you have checked out the repository https://exist.svn.sourceforge.net/svnroot/exist/trunk/eXist/webapp/functions/ to the /db/svn collection, you can get the status of its files with the following query:

The results will be: