Skip to content

Commit

Permalink
Integrate patch for --ignore-dir=match:...
Browse files Browse the repository at this point in the history
See also GH #42
  • Loading branch information
hoelzro committed Sep 10, 2014
1 parent 17504aa commit d72b708
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ack
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ sub _compile_descend_filter {
return unless $idirs && @{$idirs};

my %ignore_dirs;
my @ignore_dirs_re;

foreach my $idir (@{$idirs}) {
if ( $idir =~ /^(\w+):(.*)/ ) {
if ( $1 eq 'is') {
$ignore_dirs{$2} = 1;
}
elsif ( $1 eq 'match') {
push @ignore_dirs_re, $2;
}
else {
Carp::croak( 'Non-is filters are not yet supported for --ignore-dir' );
}
Expand All @@ -104,7 +108,8 @@ sub _compile_descend_filter {
}

return sub {
return !exists $ignore_dirs{$_} && !exists $ignore_dirs{$File::Next::dir};
return !exists $ignore_dirs{$_} && !exists $ignore_dirs{$File::Next::dir}
&& !grep { $File::Next::dir =~ $_ } @ignore_dirs_re;
};
}

Expand Down Expand Up @@ -147,12 +152,17 @@ sub _compile_file_filter {
my $dont_ignore_dir_list = $opt->{no_ignore_dirs};

my %ignore_dir_set;
my @ignore_dirs_re;
my %dont_ignore_dir_set;
my @dont_ignore_dirs_re;

foreach my $filter (@{ $ignore_dir_list }) {
if ( $filter =~ /^(\w+):(.*)/ ) {
if ( $1 eq 'is' ) {
$ignore_dir_set{ $2 } = 1;
}
elsif ( $1 eq 'match') {
push @ignore_dirs_re, $2;
} else {
Carp::croak( 'Non-is filters are not yet supported for --ignore-dir' );
}
Expand All @@ -164,6 +174,9 @@ sub _compile_file_filter {
if ( $filter =~ /^(\w+):(.*)/ ) {
if ( $1 eq 'is' ) {
$dont_ignore_dir_set{ $2 } = 1;
}
elsif ( $1 eq 'match') {
push @dont_ignore_dirs_re, $2;
} else {
Carp::croak( 'Non-is filters are not yet supported for --ignore-dir' );
}
Expand Down Expand Up @@ -196,6 +209,7 @@ sub _compile_file_filter {

my $is_ignoring = 0;

$is_ignoring = grep { $dirname =~ $_ } @ignore_dirs_re;
foreach my $dir ( @dirs ) {
if ( $ignore_dir_set{ $dir } ) {
$is_ignoring = 1;
Expand All @@ -204,7 +218,7 @@ sub _compile_file_filter {
$is_ignoring = 0;
}
}
if ( $is_ignoring ) {
if ( $is_ignoring && !grep { $dirname =~ $_ } @dont_ignore_dirs_re) {
return 0;
}
}
Expand Down

0 comments on commit d72b708

Please sign in to comment.