Ruby script to count the number of lines changed in a subversion repository

I like to set minimal targets for the amount of work I’m going to do on different projects during a week – things like word counts on papers, and so on. In that vein, here’s a short Ruby script to count the number of lines changed in a subversion repository. It returns the number of added lines and deleted lines from today’s edits. The advantage of this over most wordcount facilities is that it can be used both for programming and writing projects, and copes with an entire directory structure, not just a single file.

print “Additions: ”

puts `svn diff -r \{#{(Time.now-86400).strftime(‘%Y-%m-%d’)}\}:\{#{
(Time.now+86400).strftime(‘%Y-%m-%d’)}\} | grep \”^+\” | wc`

print “Deletions: ”

puts `svn diff -r \{#{(Time.now-86400).strftime(‘%Y-%m-%d’)}\}:\{#{
(Time.now+86400).strftime(‘%Y-%m-%d’)}\} | grep \”^\\-\” | wc`

It’s easily modified to run as a shell script, or to vary the dates.

1 comment

  1. Thanks, very useful. I had to change the quotes to ASCII or what have you — I guess my system is unicode impoverished.

    If only you could produce a script to measure whether the additions were good ones 🙂

Comments are closed.