How to skip specific files while calculating Lines of Code?

1.8k views Asked by At

I have a user case where I need to calculate Lines of Code per BUC-ID. I have achieved the same using

git log --shortstat --grep=BUC3565-EPIC16 |grep -E "fil(e|es) changed" | awk -v BUC=$i '{ inserted+=$4; deleted+=$6; delta+=$4-$6i } END {printf "%s, %s,  %s,  %s \n",BUC, inserted, deleted, delta }'

Now I have BUC-ID with multiple files. Is there any way I can just skip few files/folders and still able to calculate Lines off Code for that BUC-ID?

Basically, I need to exclude some files/folders while calculating Lines of Code. I am not able to do so because each commit has multiple files. Some should be included and some excluded...Any idea how to achieve that?

Does CLOC provide any feature to exclude files?

3

There are 3 answers

0
AlDanial On

cloc has several mechanisms to exclude files; search on "exclude" at https://github.com/AlDanial/cloc for details.

Briefly, --exclude-list-file lets you pass in a file containing names of files you want excluded, --exclude-dir lets you skip designated directories, --exclude-ext skips files with the given file extension, --exclude-lang ignores the given programming languages, --not-match-f lets you specify a regex whose matches are skipped.

0
ElpieKay On
  1. Find all the commits that's related with a BUC-ID.

    git log --pretty=%H --grep=BUC3565-EPIC16

  2. For every commit, list all the changed files excluding some files/folders.

    git show $commit --pretty=format:"" --name-only | grep -ve "foo.txt" -ve "bar/"

  3. For every file of the rest, calculate its insertions, deletions and delta.

    git show $commit --pretty=format:"" --short-stat -- $file | grep -E "fil(e|es) changed" | awk

  4. Sum up the results.

0
John Culviner On

The best way I've found to do this is to use cloc and have it ignore the very same files that are ignored by source control.

Ex:

cloc --vcs=git .