Yesterday, I wrote about how to grab Git commit statistics for author by date. I also work on some projects that use Subversion. It’s a bit tougher to grab insertion/deletion data with SVN but I came up with a way: grab the diffs for a day and parse them.

Of course, because SVN has to go and be different, the date filter also doesn’t work how you expect – it includes the first rev before that day. There’s even a note on it in the docs: http://svnbook.red-bean.com/en/1.7/svn.tour.revs.specifiers.html (the “Is Subversion a Day Early” box at the bottom).

So we’ve got to skip the first revision. Unfortunately, PowerShell processes output line by line, so we’ve got to join all the lines together, split to revs by regex, and then split out the lines again.

This works, even if it isn’t elegant. As Blaise Pascal said, “I have only made this ... longer because I have not had the time to make it shorter.” If the PowerShell pros know a better way to do this, hit me up.

Just like the git version, swap out my name for yours and the dates with todays date:

((((svn log --search chris -r '{2016-01-25T00:00:00}:{2016-01-25T23:59:59}' --diff) -join "`n" -split "-+\nr\d+", 0, "multiline") | ? { $_ }) | select -skip 1) -split "\n" | Select-String '^([+-]) ' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { New-Object psobject -Property @{ Adds = if ($_.Groups[1].Value -eq "+") { 1 } else { 0 }; Deletes = if ($_.Groups[1].Value -eq "-") { 1 } else { 0 } } } | Measure-Object -Property @("Adds","Deletes") -Sum

And the output:

Count    : 504
Average  :
Sum      : 402
Maximum  :
Minimum  :
Property : Adds

Count    : 504
Average  :
Sum      : 102
Maximum  :
Minimum  :
Property : Deletes
Post comment