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.75k stars 1.02k forks source link

Combined usage of --match-f and --no-recurse #851

Closed aladur closed 2 months ago

aladur commented 2 months ago

Describe the bug A combination of parameter --match-f with --no-recurse seems not to work.

cloc; OS; OS version

To Reproduce Step1

~/Downloads/cloc-2.02.pl --match-f='^[a-z][a-z0-9]*\.[a-z]+$' .

Output:

     277 text files.
     268 unique files.                                          
      27 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.12 s (2291.1 files/s, 562679.4 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                102           6520           3631          30726
C/C++ Header                       130           2658           2793           8567
Text                                10            234              0           3891
Qt                                   8              0              0           3359
XML                                  8              1              0           2071
C                                    7            119             95            838
SVG                                  1              0              0            239
Windows Resource File                2              6              0             72
-----------------------------------------------------------------------------------
SUM:                               268           9538           6519          49763
-----------------------------------------------------------------------------------

OK => file filter correctly applied OK => contains some pure C files in a sub folder (verified with --counted)

To Reproduce Step2

~/Downloads/cloc-2.02.pl --no-recurse .

Output:

     488 text files.
     291 unique files.                                          
     197 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.15 s (2003.0 files/s, 583572.2 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                118           6778           3974          45133
C/C++ Header                       137           3230           2831          10520
XML                                 17              1              0           3386
Qt                                   8              0              0           3359
make                                 2            436            842           3331
Text                                 6              3              0            870
Windows Resource File                2              6              0             72
Python                               1              3              1              6
-----------------------------------------------------------------------------------
SUM:                               291          10457           7648          66677
-----------------------------------------------------------------------------------

OK => --no-recurse correctly applied. No C files in sub folder counted (verified with --counted).

To Reproduce Step3

~/Downloads/cloc-2.02.pl --match-f='^[a-z][a-z0-9]*\.[a-z]+$' --no-recurse .

Output:

     488 text files.
     291 unique files.                                          
     197 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.15 s (1999.2 files/s, 582453.9 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                118           6778           3974          45133
C/C++ Header                       137           3230           2831          10520
XML                                 17              1              0           3386
Qt                                   8              0              0           3359
make                                 2            436            842           3331
Text                                 6              3              0            870
Windows Resource File                2              6              0             72
Python                               1              3              1              6
-----------------------------------------------------------------------------------
SUM:                               291          10457           7648          66677
-----------------------------------------------------------------------------------

FAIL => file filter not applied (e.g much more C++ and C Header files). OK => --no-recurse correctly applied. No C files in sub folder counted (verified with --counted).

Additional context Are the parameters somehow applied in the wrong way or is it a bug?

Thanks for this valueabe tool, worth using for any project statistics!

AlDanial commented 2 months ago

Give 1ef8059 a try

aladur commented 2 months ago

First I did the install step:

$ git clone https://github.com/AlDanial/cloc.git
$ cd cloc/Unix
$ make prefix=$HOME/temp install
...

As of today this is commit hash 1ef8059.

Repeat Step1

$ ~/temp/bin/cloc --match-f='^[a-z][a-z0-9]*\.[a-z]+$' .

Output:

     277 text files.
     268 unique files.                                          
      27 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.12 s (2317.7 files/s, 569225.2 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                102           6520           3631          30726
C/C++ Header                       130           2658           2793           8567
Text                                10            234              0           3891
Qt                                   8              0              0           3359
XML                                  8              1              0           2071
C                                    7            119             95            838
SVG                                  1              0              0            239
Windows Resource File                2              6              0             72
-----------------------------------------------------------------------------------
SUM:                               268           9538           6519          49763
-----------------------------------------------------------------------------------

OK => file filter correctly applied

Repeat Step3

$ ~/temp/bin/cloc --match-f='^[a-z][a-z0-9]*\.[a-z]+$' --no-recurse .

Output:

       0 text files.
       0 unique files.                              
       0 files ignored.

FAIL => filter does not count any file.

AlDanial commented 2 months ago

As a test, try with one of these two regexs.

  1. without a leading anchor
    $ ~/temp/bin/cloc --match-f='[a-z][a-z0-9]*\.[a-z]+$' --no-recurse .
    
  2. leading anchor followed by ./
    $ ~/temp/bin/cloc --match-f='^\./[a-z][a-z0-9]*\.[a-z]+$' --no-recurse .
    

    depending on your results I'll make further updates

aladur commented 2 months ago

Testing with the newest commit a97216f

1a. without a leading anchor and with --no-recurse

$ ~/temp/bin/cloc --match-f='[a-z][a-z0-9]*\.[a-z]+$' --no-recurse .

Output:

     309 text files.
     290 unique files.                                          
     187 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.14 s (2033.7 files/s, 566585.2 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                118           6778           3974          45133
C/C++ Header                       137           3230           2831          10520
XML                                 17              1              0           3386
Qt                                   8              0              0           3359
Text                                 6              3              0            870
make                                 1             55             31            535
Windows Resource File                2              6              0             72
Python                               1              3              1              6
-----------------------------------------------------------------------------------
SUM:                               290          10076           6837          63881
-----------------------------------------------------------------------------------

FAIL => file filter not applied OK => --no-recurse applied

1b. without a leading anchor and without --no-recurse

$ ~/temp/bin/cloc --match-f='[a-z][a-z0-9]*\.[a-z]+$' .

Output:

      393 text files.
     365 unique files.                                          
     274 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.23 s (1601.3 files/s, 577517.3 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
SVG                                 53              0              0          46239
C++                                118           6778           3974          45133
C/C++ Header                       138           3245           2849          10564
Text                                11            235              0           3895
XML                                 17              1              0           3386
Qt                                   8              0              0           3359
C                                    7            119             95            838
make                                10             87             31            725
Windows Resource File                2              6              0             72
Python                               1              3              1              6
-----------------------------------------------------------------------------------
SUM:                               365          10474           6950         114217
-----------------------------------------------------------------------------------

FAIL => file filter not applied

2a. leading anchor followed by ./ with --no-recurse

$ ~/temp/bin/cloc --match-f='^\./[a-z][a-z0-9]*\.[a-z]+$' --no-recurse .

Output:

     263 text files.
     254 unique files.                                          
      12 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.11 s (2310.6 files/s, 556687.9 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
C++                                102           6520           3631          30726
C/C++ Header                       129           2643           2775           8523
Qt                                   8              0              0           3359
XML                                  8              1              0           2071
Text                                 5              2              0            866
Windows Resource File                2              6              0             72
-----------------------------------------------------------------------------------
SUM:                               254           9172           6406          45617
-----------------------------------------------------------------------------------

OK => file filter applied OK => --no-recurse applied

2b. leading anchor followed by ./ without --no-recurse

$ ~/temp/bin/cloc --match-f='^\./[a-z][a-z0-9]*\.[a-z]+$' .

Output:

       0 text files.
       0 unique files.                              
       0 files ignored.

FAIL => wrong file filter applied, no file counted

AlDanial commented 2 months ago

Please try 3f7ded9

aladur commented 2 months ago

Tested again with 8297197:

The initial test cases Step1 - Step3 now work as expected. Thanks for the very quick response and fix.