Export Subversion Log to CSV

Is there an easy way to export subversion logs to a CSV file?

I want to use them to get closer to my hours spent on the project, and it will be easy to do this in a spreadsheet.

Thanks.

+6
svn logging
source share
5 answers

This short Python script will provide CSV with SVN log output:

#!/usr/bin/env python import csv import subprocess import sys import xml.etree.cElementTree as etree log_text = subprocess.Popen(['svn', 'log', '--xml'] + sys.argv[1:], stdout=subprocess.PIPE).communicate()[0] log_xml = etree.XML(log_text) csv_writer = csv.writer(sys.stdout) for child in log_xml.getchildren(): csv_writer.writerow([ child.attrib['revision'], child.findtext('date'), child.findtext('author').encode('utf-8'), child.findtext('msg').encode('utf-8'), ]) 

It passes command line arguments to the calling SVN call, so if you want to view version 34 and later, you can call it like this:

 $ svnlog2csv -r 34:HEAD >my_spreadsheet.csv 
+9
source share

Thanx for the script! I added this small modification because our SVN repository is UTF-8 with accented characters (French) and script borked:

 #!/usr/bin/env python import csv import subprocess import sys import xml.etree.cElementTree as etree import codecs log_text = subprocess.Popen(['svn', 'log', '--xml'] + sys.argv[1:], stdout=subprocess.PIPE).communicate()[0] log_xml = etree.XML(log_text) csv_writer = csv.writer(sys.stdout) for child in log_xml.getchildren(): csv_writer.writerow([ child.attrib['revision'], child.findtext('date'), child.findtext('author'), child.findtext('msg').encode("utf-8"), ]) 

Greetings

+2
source share

Thanks, very helpful. I found that on Windows computers python csv_writer is waiting for the binary to exit, otherwise additional carriage messages are received. The following script handles this case and also removes new lines in the middle of the commit messages (replaced by a forward slash) to provide single-line output.

 #!/usr/bin/env python import csv import subprocess import sys import xml.etree.cElementTree as etree log_text = subprocess.Popen(['svn', 'log', '--xml'] + sys.argv[1:], stdout=subprocess.PIPE).communicate()[0] log_xml = etree.XML(log_text) if sys.platform == "win32": import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) csv_writer = csv.writer(sys.stdout) for child in log_xml.getchildren(): csv_writer.writerow([ child.attrib['revision'], child.findtext('date'), child.findtext('author'), child.findtext('msg').encode("utf-8").replace('\n','/'), ]) 

(Now who else wants, svn log took the same options as git log ?? ;-)

+2
source share

Another quick fix with which I was very successful is here on the Chris blog . This is a Java program that quickly converts it to a CSV file. You can also use the online version that is shown there. He usually posts JavaScript articles, but I think he knows Java too, as they are supposedly very similar.

+1
source share

I found this handy little script

 svn log -r {2015-05-01}:{2015-05-31} http://svn.company.co.id/dev/ | tr -d '\n' | sed -r 's/-{2,}/\n/g' | sed -r 's/ \([^\)]+\)//g' | sed -r 's/^r//' | sed -r "s/[0-9]+ lines?//g" | sort -g | sed 's/ | /;/g' > list.csv 

which exports an svn log from dates from May 1, 2015 to May 31, 2015 list.csv .. here I use a semi-colon as delimiters .. because my developers use commas in their notes ..

0
source share

All Articles