Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ignore .svn directories when using sloccount?

Tags:

svn

I'm trying to use sloccount from within hudson to gather statistics on our codebase, however by default sloccount collects information on all files, even those which are "hidden" (eg. .hideme). This means the statistics are skewed since they include numbers from files within the .svn directories.

Is there any way I can tell sloccount to correctly ignore any files/directories which start with a .?

like image 486
Phillip B Oldham Avatar asked May 25 '10 12:05

Phillip B Oldham


4 Answers

This syntax is easier to maintain and to extend (which is highly important when you need to exclude several directories):

sloccount --duplicates --wide --details . | grep -v -e '.svn' > sloccount.sc

Example of exclusions chain:

sloccount --duplicates --wide --details . | grep -v -e '.svn' -e 'thirdparty'  > sloccount.sc


NB: I use it and it works on my Jenkins

like image 138
Destroyica Avatar answered Nov 09 '22 17:11

Destroyica


You could edit the source code of sloccount to not search in directories that begin with a period. Otherwise, here is something I cooked up on the command line. Basically, you can specify a list of file paths on the command line as arguments to sloccount and it will analyze only those files. So this will find all files under PWD, excluding hidden files, and then pass them as argument to sloccount.

find . \( ! -regex '.*/\..*' \) -type f | \
tr '\n' ' ' | \
xargs sloccount
like image 43
Dave Avatar answered Nov 09 '22 16:11

Dave


My final approach was to remove the .svn directories from the sed output:

sloccount --wide --details $DIR | sed "/\/\.svn\//d" > sloccount.sc
like image 4
Phillip B Oldham Avatar answered Nov 09 '22 16:11

Phillip B Oldham


Use this:

find . -path '*/.*' -prune -o -type f -exec sloccount {} \+

-exec avoids the xargs hacks seen in some of the other replies. This is the find-included xargs support. No need to run regexps, globbing is enough. Pruning subdirs is also more efficient.

Update: also, you may want to upgrade to a more recent subversion. New checkout format (after svn upgrade) uses only a single .svn directory, so usually you can just do sloccount src now.

like image 4
Has QUIT--Anony-Mousse Avatar answered Nov 09 '22 15:11

Has QUIT--Anony-Mousse