开发者

How can I ignore .svn directories when using sloccount?

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 开发者_如何学Pythonwhich 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 .?


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


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


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

sloccount --wide --details $DIR | sed "/\/\.svn\//d" > sloccount.sc


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.


I'm using the following ant target to build a "sloccount.sc" without files in ".svn":

<target name="sloccount">
    <echo message="build sloccount report" />
    <exec executable="sloccount" failonerror="true">
        <arg value="--details" />
        <arg value="--wide" />
        <arg value="source_folder" />
        <redirector output="sloccount.sc">
            <outputfilterchain>
                <linecontains negate="true">
                    <contains value=".svn" />
                </linecontains>
            </outputfilterchain>
        </redirector>
    </exec>
</target>

Simply replace "source_folder" by the name of the source folder you want to scan and tell Jenkins to build ant target "sloccount".

Note that this requires ant 1.7.1 or later.


One can ignore .svn directories by collecting files from all other directories using find:

find . -not -wholename '*/.svn/*' -type f | xargs sloccount
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜