AlDanial / cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
GNU General Public License v2.0
19.78k stars 1.02k forks source link

Request: Utilization --git-diff-all option and --exclude-list-file option at the same time #735

Closed ShunMD closed 1 year ago

ShunMD commented 1 year ago

I would like to request the ability to use the --git-diff-all option and the --exclude-list-file or --list-fileoption at the same time.

As a frequent user of cloc, I have found it to be an incredibly useful tool for counting lines of code. However, I have noticed that it is currently not possible to use the --git-diff-all option and the --exclude-list-file or --list-file options at the same time. I believe that the ability to use these options together would provide users with even more flexibility and control over the counting process.

I understand that implementing this feature may require some effort and I appreciate your consideration of my request.

Thank you for your time and for your work on the cloc tool.

AlDanial commented 1 year ago

Supporting --list-file with the --git-diff-* isn't necessary. If you're providing names to diff directly, then you just need --diff --list-file without --git-* options. Otherwise 38782a3 will do what you want, ie, --git-diff-all --exclude-list-file.

ShunMD commented 1 year ago

Thank you for the quick response. I appreciate your guidance and the work you've done on cloc.

I tried your suggestion with 38782a3, but I'm still having issues using --git-diff-all and --exclude-list-file together. It seems that when using --git-diff-all option, both --list-file and --exclude-list-file options are not functioning as expected.

Here's a breakdown of the steps I followed during my investigation:

environments

cloc --git 76617fa8

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JSON                             2              0              0          15842
JavaScript                     351           3633           4432          14826
Markdown                       241           4330             31          14121
YAML                             2              8              1             29
INI                              1              1              0             10
Bourne Shell                     1              1              1              3
-------------------------------------------------------------------------------
SUM:                           598           7973           4465          44831
-------------------------------------------------------------------------------

From the results, we can identify the line counts for each language.

cloc --git 76617fa8 --exclude-list-file

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JSON                             2              0              0          15842
Markdown                        20            793             31           4522
YAML                             2              8              1             29
JavaScript                       1              8             12             20
INI                              1              1              0             10
Bourne Shell                     1              1              1              3
-------------------------------------------------------------------------------
SUM:                            27            811             45          20426
-------------------------------------------------------------------------------

From the results, it is evident that approximately 14,000 lines of JavaScript were excluded due to exclude option.

cloc --git 76617fa8 --list-file

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JavaScript                     350           3625           4420          14806
Markdown                       221           3537              0           9599
-------------------------------------------------------------------------------
SUM:                           571           7162           4420          24405
-------------------------------------------------------------------------------

From the results, we can ascertain the line counts within the src/ folder that is mentioned in exclude_list.txt.

cloc --git d0576a25 --exclude-list-file

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JSON                             2              0              0           7900
Markdown                        19            741             14           4175
YAML                             2              8              1             29
JavaScript                       1              8             12             18
INI                              1              1              0              9
Bourne Shell                     1              1              1              3
-------------------------------------------------------------------------------
SUM:                            26            759             28          12134
-------------------------------------------------------------------------------

In the commit d0576a25, there isn't approximately 14,000 lines of JavaScript too in the case of using --exclude-list-file.

cloc --git-diff-all --exclude-list-file

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JSON
 same                            0              0              0           4352
 modified                        2              0              0           1626
 added                           0              0              0           9864
 removed                         0              0              0           1922
JavaScript
 same                            0              0             11             17
 modified                        1              0              0              1
 added                           0              0              1              2
 removed                       334           3497           4224          14186
Markdown
 same                            3             73             14           3967
 modified                       16              0              0            203
 added                           1             52             17            352
 removed                       173           2916              0           8109
YAML
 same                            1              0              1             28
 modified                        1              0              0              1
 added                           0              0              0              0
 removed                         0              0              0              0
INI
 same                            0              0              0              9
 modified                        1              0              0              0
 added                           0              0              0              1
 removed                         0              0              0              0
Bourne Shell
 same                            1              1              1              3
 modified                        0              0              0              0
 added                           0              0              0              0
 removed                         0              0              0              0
-------------------------------------------------------------------------------
SUM:
 same                            5             74             27           8376
 modified                       21              0              0           1831
 added                           1             52             18          10219
 removed                       507           6413           4224          24217
-------------------------------------------------------------------------------

The results indicate that exclude option has not excluded approximately 14,000 lines of JavaScript.

I would appreciate it if you could check this once again. Thank you for your understanding and assistance.

AlDanial commented 1 year ago

My code change only recognized individual files in the exclusion list file. Your src directory therefore didn't match anything. I'll improve the fix to recognize directories too.

AlDanial commented 1 year ago

Please give 40dc7e9 a try. These commands now give believable results for me:

  cloc --git-diff-all --exclude-list-file exclude_list.txt d0576a2594 76617fa
  cloc --git-diff-all d0576a2594 76617fa

where exclude_list.txt only contains src.

ShunMD commented 1 year ago

Thank you for addressing my concerns.
In 40dc7e9, both --git-diff-all and --exclude-list-file are functioning simultaneously as expected.

I truly appreciate your work.

ShunMD commented 1 year ago

However, on a separate note, I've noticed that --git-diff-all and --list-file are not meeting the intended behavior.

While my main requests have been resolved, I thought it would be prudent to report this for your reference.

only --git-diff-all

$ cloc --git-diff-all d0576a2594 76617fa
...
-------------------------------------------------------------------------------
SUM:
 same                          415           5230           4230          30257
 modified                      117              0              4           2178
 added                          66            824            231          12396
 removed                         1             23             17           1989
-------------------------------------------------------------------------------

--git-diff-all & --exclude-list-file

$ cloc --git-diff-all d0576a2594 76617fa --exclude-list-file=exclude
...
-------------------------------------------------------------------------------
SUM:
 same                            5             74             27           8376
 modified                       21              0              0           1831
 added                           1             52             18          10219
 removed                         0              0              1           1927
-------------------------------------------------------------------------------

--git-diff-all & --list-file

$ cloc --git-diff-all d0576a2594 76617fa --list-file=exclude
...
-------------------------------------------------------------------------------
SUM:
 same                          415           5230           4230          30257
 modified                      117              0              4           2178
 added                          66            824            231          12396
 removed                         1             23             17           1989
-------------------------------------------------------------------------------  
AlDanial commented 1 year ago

Initially I thought --list-file wouldn't be needed but if it specifies directories then yes, I'll need to make modifications. I'll have time for this update over the weekend.

AlDanial commented 1 year ago

673159c should work the way you expect, give it a shot.

ShunMD commented 1 year ago

Sorry for the delayed response.

Thank you for addressing this amidst your busy schedule. The commit with hash 673159c worked! Much appreciated!