Skip to content

Commit

Permalink
skip files with explicitly excluded extensions w/--diff, #625
Browse files Browse the repository at this point in the history
also add another test to skip directories from appearing
in --ignored output
  • Loading branch information
AlDanial committed Dec 4, 2021
1 parent 8a0fc0b commit 3cd69a3
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -5364,6 +5364,9 @@ sub make_file_list { # {{{1
} elsif (!defined $language) {
$rh_ignored->{$F} = "unable to associate with a language";
next;
} elsif ($language eq "(unknown)") {
# entry should already be in %{$rh_ignored}
next;
}
printf $fh "%d%s%s%s%s\n", $size_in_bytes, $separator,
$language, $separator, $file;
Expand Down Expand Up @@ -5659,7 +5662,7 @@ sub files { # {{{1
$File::Find::name, $nBytes, $is_dir, $is_bin if $opt_v > 5;
$is_bin = 0 if $opt_unicode and unicode_file($_);
$is_bin = 0 if $opt_read_binary_files;
if ($is_bin) {
if ($is_bin and !$is_dir) {
$Ignored{$File::Find::name} = "binary file";
printf "files(%s) binary file\n", $File::Find::name if $opt_v > 5;
}
Expand Down
8 changes: 8 additions & 0 deletions Unix/t/01_opts.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use File::Copy "cp";
use Cwd;
#use YAML qw(LoadFile);
my @Tests = (

{
'name' => '--exclude-dir 1 (baseline for github issue #82)',
'args' => '--exclude-dir cc ../tests/inputs/dd',
Expand Down Expand Up @@ -633,6 +634,13 @@ my @Tests = (
'ref' => '../tests/outputs/issues/628/results.yaml',
},

{
'name' => 'diff with dir of excluded extensions, #625',
'cd' => '../tests/inputs/issues/625',
'args' => '--diff old new',
'ref' => '../tests/outputs/issues/625/results.yaml',
},

);

# Special cases:
Expand Down
5 changes: 4 additions & 1 deletion cloc
Original file line number Diff line number Diff line change
Expand Up @@ -5378,6 +5378,9 @@ sub make_file_list { # {{{1
} elsif (!defined $language) {
$rh_ignored->{$F} = "unable to associate with a language";
next;
} elsif ($language eq "(unknown)") {
# entry should already be in %{$rh_ignored}
next;
}
printf $fh "%d%s%s%s%s\n", $size_in_bytes, $separator,
$language, $separator, $file;
Expand Down Expand Up @@ -5673,7 +5676,7 @@ sub files { # {{{1
$File::Find::name, $nBytes, $is_dir, $is_bin if $opt_v > 5;
$is_bin = 0 if $opt_unicode and unicode_file($_);
$is_bin = 0 if $opt_read_binary_files;
if ($is_bin) {
if ($is_bin and !$is_dir) {
$Ignored{$File::Find::name} = "binary file";
printf "files(%s) binary file\n", $File::Find::name if $opt_v > 5;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/inputs/issues/625/new/hello.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// hello.C
#include <iostream>
int main ()
{
std::cout << "hello" << std::endl; // comment 1
std::cout << "again" << std::endl; /* comment
2 */
}
1 change: 1 addition & 0 deletions tests/inputs/issues/625/old/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release_notes-?.??.txt
56 changes: 56 additions & 0 deletions tests/outputs/issues/625/results.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.91
elapsed_seconds : 0.00797080993652344
n_files : 1
n_lines : 8
files_per_second : 125.457765015554
lines_per_second : 1003.66212012443
report_file : /home/al/git-cloc/tests/outputs/issues/625/results.yaml
added :
'C++' :
blank : 0
code : 6
comment : 2
nFiles : 1
same :
'C++' :
blank : 0
code : 0
comment : 0
nFiles : 0
modified :
'C++' :
blank : 0
code : 0
comment : 0
nFiles : 0
removed :
'C++' :
blank : 0
code : 0
comment : 0
nFiles : 0
SUM :
added :
comment : 2
blank : 0
code : 6
nFiles : 1
same :
comment : 0
blank : 0
code : 0
nFiles : 0
modified :
comment : 0
blank : 0
code : 0
nFiles : 0
removed :
comment : 0
blank : 0
code : 0
nFiles : 0

0 comments on commit 3cd69a3

Please sign in to comment.