cloc
cloc copied to clipboard
Exact line modified
Hello, I've used cloc for a while now and I find it very useful, specially the diff functionality. But I was wondering if there is an option to print out exactly which lines have been modified, the exact line numbers for each file pair analyzed, in the report, or maybe in the alignment file (when using --diff-alignment). If this is not currently supported, which is the best way to tackle this modification? I've been taking a look at the code, but my Perl is terrible. Thanks for the tool and for your time Aurelio
There isn't an option to print line numbers where diff's occur. Adding such a feature wouldn't be simple because blank lines are removed early in the processing chain; the positions of removed blank lines would need to be maintained and passed along.
Having said that, line number information (ignoring blanks) is kept in the diff code. If you're curious, uncomment lines 10237 and 10238 at the bottom of the subroutine array_diff(). This is from cloc-1.72.pl:
10236 }
10237 use Data::Dumper::Simple;
10238 print Dumper($rah_diff_L, $rah_diff_R);
10239
10240 print "<- array_diff\n" if $opt_v > 2;
10241 } # 1}}}
then run with --diff
. There will be a lot of output. If the line numbers look meaningful I can make the output more legible.
In the output generated by that modification, are the line numbers returned absolute (ignoring blank lines, already removed) or are they further divided into comment and code lines? For example, if it says a certain line is the 7th, is that the 7th line in the program (not counting blanks) or the 7th line OF CODE (ignoring blanks and comments). Thank you for the answer
The answer is actually both: array_diff()
is called four times for each file pair. The first two times lnum
has absolute line counts (ignoring blanks). The next two times it computes the differences in code only and in comments only so there lnum
is relative.