Pulling Subversion Logs for a Single User

There are many times during a project where I use the svn log command in order to see what has changed and to get a feel for the pace of development. It’s also great when you’re dealing with clients; you’re only one command away from telling an inquisitive client exactly who did what task and when they did them. However, svn log is missing one important feature — the ability to filter by a particular username. When I asked in #svn on freenode, they suggested I use the --xml option and parse the resulting output.

The following is what I came up with. It’s a ruby script that uses the delightful Hpricot gem to parse the xml. It takes one argument, the subversion username that you wish to retrieve the logs for. I hope that it’s useful for someone else! You can curl it from http://pastie.textmate.org/197763.txt if that makes it easier, too.

[ruby]
#!/usr/bin/ruby
require ‘rubygems’
require ‘hpricot’

username = ARGV[0]
if username.nil? || username == “”
puts “Please specify the username to cull log entries for.”
exit
end

puts “Requesting SVN log, this may take a bit.”

doc = IO.popen(“svn log –xml”) do |f|
Hpricot.XML(f)
end

entries = doc.search(“logentry”).find_all do |entry|
(entry/”author”).innerHTML == username
end

entries.each do |entry|
revision = entry.attributes["revision"]
author = (entry/”author”).innerHTML
date = (entry/”date”).innerHTML
msg = (entry/”msg”).innerHTML

puts “r#{revision} – #{author}”
puts “#{date}”
puts “#{msg}”
puts “-”*80
end
[/ruby]

  • http://mumuki2.blogspot.com jw

    Nice. Thanks

  • Khajan singh

    you no need to do this long process if you are on linux you can retrieve logs by user with a easy command .
    svn log -r {start date}:{end date} -v | sed -n ‘/username/,/—–$/ p’If you wants to retrieve svn logs on the basis of username and between the given date range then you need use svn log -r {startDate}:{endDate} which is piped with sed command for username .More Information are given on the following blog link. http://khajan.blog.co.in/2011/01/05/retrieve-svn-logs-by-username/ please follow the link you will found a easy command to get all the logs between the given date range of specific user…………………