cloc

how do I output the difference in source files with cloc?


I am counting lines with cloc using this command:

cloc --ignore-case --ignore-whitespace --diff src-copy/file.c src/file.c

and it tells me that I added 103 lines.

When I count the same file with 'git diff' it tells me that I have added 136 lines:

git diff --stat --ignore-blank-lines -w src-copy/file.c src/file.c

How can I verify that cloc counts the lines correctly? Is there any option to output the actual difference of both files, so I can visually inspect and understand why the results of both programs do not match ?


Solution

  • You can get a sense of what cloc thinks is different between the two files by having cloc strip comments from the files then doing a visual diff of the code-only files:

      cloc --strip-comments nc --original-dir src-copy/file.c src/file.c
      vimdiff src-copy/file.c.nc src/file.c.nc
    

    (or replace vimdiff with the tool of your choice). That will at least eliminate comment differences. Anything flagged by your diff tool should be recognized by cloc as a difference in the count for code changes.

    cloc doesn't have an option to show the internals of the diff comparisons. https://github.com/AlDanial/cloc/issues/152 shows a way to add debug statements in the tool to show some of this but the output isn't pretty.