25

I have been tasked with figuring out how many lines of code I've written this year. Not very exciting for a number of reasons, but it seems like it could make a nice SO question.

So in your favorite version control tool, how do you tell how many lines of code have been modified? In my particular answer blank lines and comments happen to count to simplify the time allotted to determining the answer, but feel free to elaborate.

In my particular case I'm using svn, so I'm going to get rid of all the --- and other misc output that svn log and svn diff output.

Nathan Feger
  • 19,122
  • 11
  • 62
  • 71
  • 17
    The fact that someone is asking this question makes me concerned that they think this metric means something. – recursive Oct 08 '09 at 14:30
  • @recursive - Jeff Atwood seems to say it measures something. http://www.codinghorror.com/blog/archives/000637.html – Maslow Oct 08 '09 at 14:39
  • @Maslow: I don't think anyone argues that it measures something. The argument is over whether it measures something that has a meaning regarding project progress, programmer effectiveness etc. But there is very little correlation between lines of code and any useful information about the code. It's not even the case that it the opposite is true: While it's very easy to show cases where fewer lines are better, that doesn't mean that the fewer lines are written the better it is. The only thing being clear is that, wherever the number of lines is watched for, the code sooner or later gets worse. – sbi Oct 09 '09 at 10:37
  • I like to know how many lines where removed (as part of a refactoring effort, for example). – Jeff B Jul 24 '13 at 14:29
  • I think this is a perfectly valid question - not sure what you're getting at recursive. Here in Canada I can use this on my SR&ED government funding reports. – Kevin Parker Jul 31 '13 at 19:07
  • @sbi From what I've read... it is a good measure of productivity unless you use it to measure productivity. Meaning, if anyone knows you're using it to measure productivity, they will start gaming the metric and you'll get really ugly code. That said, I landed here because I was trying to pull out some silly trivia questions for an annual company meeting "guess how many lines of code we produced in the last year" kind of thing – Kip Apr 29 '14 at 18:21
  • @Kip: The best C++ programmers I have seen write comparatively dense code. The worst C++ programmers I have seen write bad, chatty C code. – sbi Apr 29 '14 at 22:04

7 Answers7

28

Use StatSVN. I use it at work and it's great, it'll break down LOC by developer by month. It'll draw pretty graphs, tell you what day of the week and what time you check in the most code. It'll tell you exactly what you need to know.

Roland Rabien
  • 8,750
  • 7
  • 50
  • 67
  • I'm running it now, I'm not sure how it deals with branches though. – Nathan Feger Oct 08 '09 at 15:03
  • @Nathan: I just tried it. By default, it will count branched off code as if it was typed. But from what I saw it seems to be possible to have it disregard branches completely. Then only code that got merged into the trunk would show up. But I have only very quickly browsed through the docs... – sbi Oct 08 '09 at 16:44
13

The simplest solution:

svn diff -x --ignore-eol-style -x -w http://svn/tags/releases/1.0 http://svn/tags/releases/2.0/ |diffstat

this is very rudimentary and does not exclude blank line inserts and so on, but perhaps it's good enough?

Bartosz Radaczyński
  • 18,396
  • 14
  • 54
  • 61
3

Fisheye can tell you how many lines of code were committed per developer. There is a nice charting feature that can give you pretty graphs for this.

Taylor Leese
  • 51,004
  • 28
  • 112
  • 141
1

I also tried to solve task such as "how many lines were removed, added or just changed in selected period of time". So I wrote simple shell script (for Linux only). It gathers some sipmle statistics about code modifications. More details and shared script you may find here:

http://cyber-fall.blogspot.com/2011/10/tools-linux-svn-generate-statistic.html

Hope it will help to you and to others!

Gadget
  • 474
  • 1
  • 5
  • 12
0

If you are stuck on cvs:

cvs annotate > annotate.txt
rem remove the portion before the name
sed "s/^[0-9. (]*//" annotate.txt > annotate2.txt
rem remove the portion after the name
sed "s/[ ].*$//" annotate2.txt > annotate3.txt
sort annotate3.txt > annotate4.txt
uniq -c annotate4.txt > annotate5.txt

http://jamesjava.blogspot.com/2007/01/who-has-changed-most-lines-in-cvs.html

James A. N. Stauffer
  • 2,649
  • 3
  • 22
  • 32
-1

In Clearcase, take the config spec and add:

time  <date-time>
<rules for choosing branches or labels>
end time

Make a second view, and compare the two. If multiple developers are working on the same files, I have no clue. I can't say I'm thrilled by using Clearcase, ever.

Dean J
  • 39,360
  • 16
  • 67
  • 93
-2

If you are using subversion you can use the svn log command with the --xml switch and you can pull the lines of code from there. You can see the options of svn log using svn help log. Since your output is xml you can run through this xml and aggregate your line counts in code and go from there.

Michael Mann
  • 777
  • 3
  • 9