Is there any good tool that computes the number of changed lines of code over a certain time period in a mercurial repository? Something along the lines of statsvn would be great, but anything counting the number of changed lines of code within 6 months will do (including a clever combination of arguments to hg log). Thanks.
PS: Please do not discuss the purpose of measuring this number ;)
Edit:
hg diff
andhg log
both support a--stat
option that can do this for you, only better and quicker.I made an alias called
lines
to count changed lines (not necessarily lines of code) for me. Try putting this alias in your .hgrc file:Then pass it the revision first, followed by any optional arguments:
hg lines tip
orhg lines 123:456 -u brian
Sometimes you want to know the number of lines changed excluding whitespace-only changes. This requires using
diff -w
underneath instead oflog -p
. I set up alinesw
alias for this:hg linesw tip
orhg lines 123:456
Note they behave slightly differently because
diff
andlog
behave differently -- for example,log
will take a--user
parameter whilediff
will not, and when passing a range,log
will show changes commited in the first revision given in the range, whilediff
will not.This has only been tested using bash.
I needed to do this, and spent quite a bit of time with the hg churn extension and similar solutions.
In the end, I found that what worked best for me was CLOC (Count Lines of Code): http://cloc.sourceforge.net/
You can give it two folders containing two versions of a project, and it will count all of the lines that are the same, modified, added, removed. It recognises multiple languages and itemises code, comments and blank lines.
To use it, I pulled out the two versions of my code from Hg into two parallel folders, and then used cloc --diff --ignore-whitespace
The hg churn extension is what you want.
You can get visual results with hg activity or hg chart.