Subversion Revision History, One Line Per Revision
Develop | Posted March 04, 2009

I wanted something that I thought would be pretty simple to get: a list of revisions to a branch in Subversion, one revision per line. For each revision, I wanted a single entry, regardless of how many files were included in that revision. Further, I only wanted to know some basic information: revision number, who did it, the date, and the first 80 characters or so of the comment.

I was not able to figure out how to get one of the Subversion commands by itself to do that, but I was able to use the XML output from svn log to ultimately get what I wanted. This is the Subversion command I ended up using:

   svn log --stop-on-copy --xml http://server/repos/branches/mybranch

I took the output from that command and ran it through a Groovy script that I hacked out really quickly in order to create the one line per revision output that I wanted. XSLT might have been more appropriate, but not being much of an XSLT guru, I went with what I knew:




// ParseSVN.groovy
//
// Given the XML output from this SVN command:
//
// $ svn log --stop-on-copy --xml <URL>
//
// Create a row per revision, suitable for something like a wiki
//
// if not enough args, cannot do anything

if (args.length < 1) {
println "Usage: ParseSVN <xml file from svn>"
return
}
svnXMLFile = args[0]

// open up the SVN output so that we can just exit now if there is an error
try {
svnXML = new XmlSlurper().parse(new File(svnXMLFile))
}

catch( ex ) {
println "Unable to open: $svnXMLFile - ${ex.class.name} : ${ex.message}"
return
}


// for each SVN entry create a row
entries = svnXML.logentry.findAll {
it.@revision.text()
}
entries.each {
revision = it.@revision.toString()
author = it.author.toString()
date = it.date.toString()
msg = it.msg.toString()
if (msg.size() > 80) {
msg = msg.substring(0,79)
msg += " ..."
}
msg = msg.replace('
'
, ' ')
tableRow = "||$revision||$author||$date||$msg||"

println tableRow
}



Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox