tags:

views:

955

answers:

4

I've spent most of the day making what are basically some housekeeping changes to the codebase of one of our projects (replacing all System.out.println() calls with log4j).

I'm kind of curious how many lines of code I've updated with this set of changes.

Is there anyway with cvs diff or another command to get an accurate count of how many lines have changed?

I've tried

cvs diff -b -B -R

to get all of the changes in the working directory (and recursively the subdirectories), but for each file changed it also prints out file/version information, which makes just counting the lines of output useless.

Any ideas?

+1  A: 

You can simply pipe output of cvs diff to diffstat.

sanxiyn
This works well, although it seems to double-count files like "jsp/blah.jsp" and "blah.jsp". Didn't know about diffstat before, thanks!
matt b
A: 

What about verify that you've changed all instances with something like:

find . | egrep -v -e '(CVS|<other patterns you don't want>)' | \
    xargs egrep -e 'System\.out\.println[(][)]' | wc -l

that should give you zero.

Then replacing the regex in the second egrep with 'log4j' should have wc -l returning the number of lines you've changed.

HTH.

cheers,

Rob

Rob Wells
+1  A: 

Filter out extra lines from the diff output and then count the lines.

For example, grep only lines starting with < or >

cvs diff -b -B -R | egrep '^<|>' | wc -l
Maglob
This is what I ended up using after all, a few seconds before you posted - thanks
matt b
using this a modified line will count twice right?
f4
A: 

The diffstat utility is a nice tool for getting some simple metrics from the output of cvs, svn or other diffs.

jmcnamara