Skip to content

Commit fcde6f6

Browse files
committed
implement --include-submodules (for --vcs=git), #944
1 parent 17bf0b8 commit fcde6f6

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ release_notes-?.??.txt
44
# Visual Studio Code and extensions
55
.vstags
66
.vscode/perl-lang
7+
.gitmodules
8+
Unix/cloc_submodule_test

Unix/cloc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ my (
196196
$opt_v ,
197197
$opt_vcs ,
198198
$opt_version ,
199+
$opt_include_submodules ,
199200
$opt_include_content ,
200201
$opt_exclude_content ,
201202
$opt_exclude_lang ,
@@ -332,6 +333,7 @@ my $getopt_success = GetOptions( # {{{1
332333
"v|verbose:i" => \$opt_v ,
333334
"vcs=s" => \$opt_vcs ,
334335
"files-from=s" => \$opt_vcs , # synonym
336+
"include-submodules" => \$opt_include_submodules ,
335337
"version" => \$opt_version ,
336338
"write_lang_def|write-lang-def=s" => \$opt_write_lang_def ,
337339
"write_lang_def_incl_dup|write-lang-def-incl-dup=s" => \$opt_write_lang_def_incl_dup,
@@ -443,6 +445,7 @@ load_from_config_file($config_file, # {{{2
443445
\$opt_3 ,
444446
\$opt_v ,
445447
\$opt_vcs ,
448+
\$opt_include_submodules ,
446449
\$opt_version ,
447450
\$opt_write_lang_def ,
448451
\$opt_write_lang_def_incl_dup,
@@ -714,6 +717,7 @@ if (defined $opt_vcs) {
714717
}
715718
if ($opt_vcs eq "git") {
716719
$opt_vcs = "git -c \"safe.directory=*\" ls-files";
720+
$opt_vcs .= " --recurse-submodules" if $opt_include_submodules;
717721
my @submodules = invoke_generator("git -c \"safe.directory=*\" submodule status", \@ARGV);
718722
foreach my $SM (@submodules) {
719723
$SM =~ s/^\s+//; # may have leading space
@@ -1931,14 +1935,13 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
19311935
--files-from=<CMD> Synonym for --vcs=<CMD>.
19321936
--vcs=<CMD> Invoke a system call to <CMD> to obtain a list of
19331937
files to work on. If <CMD> is 'git', then will
1934-
invoke 'git ls-files' to get a file list and
1935-
'git submodule status' to get a list of submodules
1936-
whose contents will be ignored. See also --git
1937-
which accepts git commit hashes and branch names.
1938-
If <VCS> is 'svn' then will invoke 'svn list -R'.
1939-
The primary benefit is that cloc will then skip
1940-
files explicitly excluded by the versioning tool
1941-
in question, ie, those in .gitignore or have the
1938+
invoke 'git ls-files' to get a file list. Submodules
1939+
are ignored unless --include-submodules is also
1940+
given. See also --git which accepts git commit hashes
1941+
and branch names. If <VCS> is 'svn' then will invoke
1942+
'svn list -R'. The primary benefit is that cloc will
1943+
then skip files explicitly excluded by the versioning
1944+
tool in question, ie, those in .gitignore or have the
19421945
svn:ignore property.
19431946
Alternatively <CMD> may be any system command
19441947
that generates a list of files.
@@ -2251,6 +2254,8 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
22512254
Count only the given comma separated, case-
22522255
insensitive languages L1, L2, L3, et cetera. Use
22532256
--show-lang to see the list of recognized languages.
2257+
--include-submodules When using --vcs=git, include files in git
2258+
submodules.
22542259
--match-d=<regex> Only count files in directories matching the Perl
22552260
regex. For example
22562261
--match-d='/(src|include)/'
@@ -15279,6 +15284,7 @@ sub load_from_config_file { # {{{1
1527915284
$rs_3 ,
1528015285
$rs_v ,
1528115286
$rs_vcs ,
15287+
$rs_include_submodules ,
1528215288
$rs_version ,
1528315289
$rs_write_lang_def ,
1528415290
$rs_write_lang_def_incl_dup,
@@ -15391,6 +15397,7 @@ sub load_from_config_file { # {{{1
1539115397
} elsif (!defined ${$rs_unicode} and /^unicode/) { ${$rs_unicode} = 1;
1539215398
} elsif (!defined ${$rs_3} and /^3/) { ${$rs_3} = 1;
1539315399
} elsif (!defined ${$rs_vcs} and /^vcs(=|\s+)(\S+)/) { ${$rs_vcs} = $2;
15400+
} elsif (!defined ${$rs_include_submodules} and /^include-submodules/) { ${$rs_include_submodules} = 1;
1539415401
} elsif (!defined ${$rs_version} and /^version/) { ${$rs_version} = 1;
1539515402
} elsif (!defined ${$rs_write_lang_def} and /^(?:write_lang_def|write-lang-def)(=|\s+)(.*?)$/) { ${$rs_write_lang_def} = $2;
1539615403
} elsif (!defined ${$rs_write_lang_def_incl_dup} and /^(?:write_lang_def_incl_dup|write-lang-def-incl-dup)(=|\s+)(.*?)$/) { ${$rs_write_lang_def_incl_dup} = $2;

Unix/t/02_git.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ if (!-d 'cloc_submodule_test') {
119119
print "-" x 79, "\n";
120120
print "Directory 'cloc_submodule_test' is not found; git tests skipped.\n";
121121
print "To enable the tests, create the directory with\n";
122-
print " git clone https://github.com/AlDanial/cloc_submodule_test.git\n";
122+
print " git submodule add https://github.com/AlDanial/cloc_submodule_test.git\n";
123123
ok( 0, "git tests");
124124
print "-" x 79, "\n";
125125
} else {

cloc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ my (
199199
$opt_v ,
200200
$opt_vcs ,
201201
$opt_version ,
202+
$opt_include_submodules ,
202203
$opt_include_content ,
203204
$opt_exclude_content ,
204205
$opt_exclude_lang ,
@@ -335,6 +336,7 @@ my $getopt_success = GetOptions( # {{{1
335336
"v|verbose:i" => \$opt_v ,
336337
"vcs=s" => \$opt_vcs ,
337338
"files-from=s" => \$opt_vcs , # synonym
339+
"include-submodules" => \$opt_include_submodules ,
338340
"version" => \$opt_version ,
339341
"write_lang_def|write-lang-def=s" => \$opt_write_lang_def ,
340342
"write_lang_def_incl_dup|write-lang-def-incl-dup=s" => \$opt_write_lang_def_incl_dup,
@@ -446,6 +448,7 @@ load_from_config_file($config_file, # {{{2
446448
\$opt_3 ,
447449
\$opt_v ,
448450
\$opt_vcs ,
451+
\$opt_include_submodules ,
449452
\$opt_version ,
450453
\$opt_write_lang_def ,
451454
\$opt_write_lang_def_incl_dup,
@@ -707,6 +710,7 @@ if (defined $opt_vcs) {
707710
}
708711
if ($opt_vcs eq "git") {
709712
$opt_vcs = "git -c \"safe.directory=*\" ls-files";
713+
$opt_vcs .= " --recurse-submodules" if $opt_include_submodules;
710714
my @submodules = invoke_generator("git -c \"safe.directory=*\" submodule status", \@ARGV);
711715
foreach my $SM (@submodules) {
712716
$SM =~ s/^\s+//; # may have leading space
@@ -1923,14 +1927,13 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
19231927
--files-from=<CMD> Synonym for --vcs=<CMD>.
19241928
--vcs=<CMD> Invoke a system call to <CMD> to obtain a list of
19251929
files to work on. If <CMD> is 'git', then will
1926-
invoke 'git ls-files' to get a file list and
1927-
'git submodule status' to get a list of submodules
1928-
whose contents will be ignored. See also --git
1929-
which accepts git commit hashes and branch names.
1930-
If <VCS> is 'svn' then will invoke 'svn list -R'.
1931-
The primary benefit is that cloc will then skip
1932-
files explicitly excluded by the versioning tool
1933-
in question, ie, those in .gitignore or have the
1930+
invoke 'git ls-files' to get a file list. Submodules
1931+
are ignored unless --include-submodules is also
1932+
given. See also --git which accepts git commit hashes
1933+
and branch names. If <VCS> is 'svn' then will invoke
1934+
'svn list -R'. The primary benefit is that cloc will
1935+
then skip files explicitly excluded by the versioning
1936+
tool in question, ie, those in .gitignore or have the
19341937
svn:ignore property.
19351938
Alternatively <CMD> may be any system command
19361939
that generates a list of files.
@@ -2243,6 +2246,8 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
22432246
Count only the given comma separated, case-
22442247
insensitive languages L1, L2, L3, et cetera. Use
22452248
--show-lang to see the list of recognized languages.
2249+
--include-submodules When using --vcs=git, include files in git
2250+
submodules.
22462251
--match-d=<regex> Only count files in directories matching the Perl
22472252
regex. For example
22482253
--match-d='/(src|include)/'
@@ -15271,6 +15276,7 @@ sub load_from_config_file { # {{{1
1527115276
$rs_3 ,
1527215277
$rs_v ,
1527315278
$rs_vcs ,
15279+
$rs_include_submodules ,
1527415280
$rs_version ,
1527515281
$rs_write_lang_def ,
1527615282
$rs_write_lang_def_incl_dup,
@@ -15383,6 +15389,7 @@ sub load_from_config_file { # {{{1
1538315389
} elsif (!defined ${$rs_unicode} and /^unicode/) { ${$rs_unicode} = 1;
1538415390
} elsif (!defined ${$rs_3} and /^3/) { ${$rs_3} = 1;
1538515391
} elsif (!defined ${$rs_vcs} and /^vcs(=|\s+)(\S+)/) { ${$rs_vcs} = $2;
15392+
} elsif (!defined ${$rs_include_submodules} and /^include-submodules/) { ${$rs_include_submodules} = 1;
1538615393
} elsif (!defined ${$rs_version} and /^version/) { ${$rs_version} = 1;
1538715394
} elsif (!defined ${$rs_write_lang_def} and /^(?:write_lang_def|write-lang-def)(=|\s+)(.*?)$/) { ${$rs_write_lang_def} = $2;
1538815395
} elsif (!defined ${$rs_write_lang_def_incl_dup} and /^(?:write_lang_def_incl_dup|write-lang-def-incl-dup)(=|\s+)(.*?)$/) { ${$rs_write_lang_def_incl_dup} = $2;

0 commit comments

Comments
 (0)