Skip to content

Commit ec27504

Browse files
committed
Merge branch 'dev' of github.com:petdance/ack2 into dev
2 parents e29c9dc + 2de9b19 commit ec27504

19 files changed

+468
-32
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ stderr.log
1414
stdout.log
1515
.timings.json
1616
xt/.perlcritic-history
17+
completion.bash
18+
completion.zsh

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Before You Report an Issue...
2+
3+
Before you report an issue, please consult the [FAQ](http://beyondgrep.com/documentation/ack-2.12-man.html#faq).
4+
5+
# Reporting an Issue
6+
7+
If you have an issue with ack, please add the following to your ticket:
8+
9+
- What OS you're on
10+
- What version of ack you're using
11+
12+
Please try to reproduce your issue against the latest ack from git. If you are not able to
13+
reproduce the issue with ack built from git, you should probably file the issue anyway, as
14+
that probably means someone needs to make a release. =)
15+
16+
Also appreciated with an issue are the following:
17+
18+
- Example invocations along with expected vs received output (see [#439](https://github.com/petdance/ack2/issues/439), great job!)
19+
- A `.t` test file that tests and verifies the behavior you expect
20+
- A patch that fixes your issue
21+
22+
# Ack 1.x
23+
24+
Keep in mind that if you're using ack 1.x, you should probably upgrade, as ack 1.x is no longer supported.
25+
26+
# Getting Help
27+
28+
Also, feel free to discuss your issues on the [ack mailing list](http://groups.google.com/group/ack-users)!

Changes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
History file for ack. http://beyondgrep.com/
22

3+
NEXT
4+
====================================
5+
[FIXES]
6+
The -s flag would fail to suppress certain warnings. Thanks, Kassio
7+
Borges. (GitHub ticket #439)
8+
9+
The -w flag would fail to work properly with regex features such as
10+
alternation. Thanks to Ed Avis for the report (GitHub ticket #443)
11+
12+
The -g flag should now work faster on larger codebases. Thanks to
13+
Manuel Meurer for the report (GitHub ticket #458)
14+
15+
[ENHANCEMENTS]
16+
ack now ignores JavaScript and CSS source maps. Thanks, Chris
17+
Rebert.
18+
19+
ack now ships with customized shell completion scripts for bash and zsh.
20+
21+
322
2.13_06 Sat Jan 25 23:36:09 CST 2014
423
====================================
524
[FIXES]
625
More fixes for Windows tests. Thanks to GitHub user @ispedals.
726

27+
[ENHANCEMENTS]
28+
29+
Add docs for available colors in ack.
830

931
2.13_05 Thu Jan 9 22:41:33 CST 2014
1032
====================================

ConfigDefault.pm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ sub _options_block {
139139
--ignore-file=match:/[.]min[.]css$/
140140
--ignore-file=match:/[.]css[.]min$/
141141
142+
# JS and CSS source maps
143+
--ignore-file=match:/[.]js[.]map$/
144+
--ignore-file=match:/[.]css[.]map$/
145+
142146
# PDFs, because they pass Perl's -T detection
143147
--ignore-file=ext:pdf
144148
@@ -162,7 +166,8 @@ sub _options_block {
162166
--type-add=make:ext:mak
163167
--type-add=make:is:makefile
164168
--type-add=make:is:Makefile
165-
--type-add=make:is:GNUmakefile
169+
--type-add=make:is:Makefile.Debug
170+
--type-add=make:is:Makefile.Release
166171
167172
# Rakefiles
168173
# http://rake.rubyforge.org/
@@ -330,6 +335,10 @@ sub _options_block {
330335
# http://www.r-project.org/
331336
--type-add=rr:ext:R
332337
338+
# reStructured Text
339+
# http://docutils.sourceforge.net/rst.html
340+
--type-add=rst:ext:rst
341+
333342
# Ruby
334343
# http://www.ruby-lang.org/
335344
--type-add=ruby:ext:rb,rhtml,rjs,rxml,erb,rake,spec

ConfigLoader.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ EOT
217217
* Your new option is explained when a user invokes ack --man.
218218
(See the POD at the end of ./ack)
219219
* Add your option to t/config-loader.t
220+
* Add your option to t/Util.pm#get_options
221+
* Add your option's description and aliases to dev/generate-completion-scripts.pl
220222
* Go through the list of options already available, and consider
221223
whether your new option can be considered mutually exclusive
222224
with another option.

DESIGN.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ It seems not. Brian M. Carlson investigated this and reported his
2121
findings here: https://github.com/petdance/ack2/issues/398
2222

2323
There seemed to be no effect.
24+
25+
## Can we make --sort be the default?
26+
27+
No. Sorting the filenames requires reading in the entire directory
28+
of filenames before searching, and this can be a performance hit.
29+
In fact, it can kill ack entirely on directories with absurdly large
30+
numbers of files in them.
31+
32+
## Why not make ack use /usr/bin/env in the shebang instead of /usr/bin/perl?
33+
34+
The Perl toolchain takes care of the shebang at install time.

Makefile.PL

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ my %parms = (
5353
},
5454
MAN3PODS => {}, # no need for man pages for any of the .pm files
5555
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
56-
clean => { FILES => 'ack-2* nytprof* stderr.log stdout.log' },
56+
clean => { FILES => 'ack-2* nytprof* stderr.log stdout.log completion.*' },
5757
);
5858

5959
if ( $ExtUtils::MakeMaker::VERSION =~ /^\d\.\d\d$/ and $ExtUtils::MakeMaker::VERSION > 6.30 ) {
@@ -159,6 +159,12 @@ time-head: ack-standalone
159159
timings: ack-standalone
160160
./dev/timings.pl
161161
162+
completion.bash: pm_to_blib
163+
./dev/generate-completion-scripts.pl completion.bash
164+
165+
completion.zsh: pm_to_blib
166+
./dev/generate-completion-scripts.pl completion.zsh
167+
162168
MAKE_FRAG
163169

164170
return $postamble;

Resources.pm

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ use File::Next 1.10;
77
use warnings;
88
use strict;
99

10+
sub _generate_error_handler {
11+
my $opt = shift;
12+
13+
if ( $opt->{dont_report_bad_filenames} ) {
14+
return sub {
15+
my $msg = shift;
16+
# XXX restricting to specific error messages for now; I would
17+
# prefer a different way of doing this
18+
if ( $msg =~ /Permission denied/ ) {
19+
return;
20+
}
21+
App::Ack::warn( $msg );
22+
};
23+
}
24+
else {
25+
return sub {
26+
my $msg = shift;
27+
App::Ack::warn( $msg );
28+
};
29+
}
30+
}
31+
1032
=head1 SYNOPSIS
1133
1234
This is the base class for App::Ack::Resources, an iterator factory
@@ -40,7 +62,8 @@ sub from_argv {
4062
File::Next::files( {
4163
file_filter => $opt->{file_filter},
4264
descend_filter => $descend_filter,
43-
error_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
65+
error_handler => _generate_error_handler($opt),
66+
warning_handler => sub {},
4467
sort_files => $opt->{sort_files},
4568
follow_symlinks => $opt->{follow},
4669
}, @{$start} );
@@ -62,8 +85,8 @@ sub from_file {
6285

6386
my $iter =
6487
File::Next::from_file( {
65-
error_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
66-
warning_handler => sub { my $msg = shift; App::Ack::warn( $msg ) },
88+
error_handler => _generate_error_handler($opt),
89+
warning_handler => _generate_error_handler($opt),
6790
sort_files => $opt->{sort_files},
6891
}, $file ) or return undef;
6992

ack

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,19 @@ sub _compile_file_filter {
172172
}
173173
}
174174

175+
my $match_filenames = $opt->{g};
176+
my $match_regex = $opt->{regex};
177+
my $is_inverted = $opt->{v};
178+
175179
return sub {
180+
if ( $match_filenames ) {
181+
if ( $File::Next::name =~ /$match_regex/ && $is_inverted ) {
182+
return;
183+
}
184+
if ( $File::Next::name !~ /$match_regex/ && !$is_inverted ) {
185+
return;
186+
}
187+
}
176188
# ack always selects files that are specified on the command
177189
# line, regardless of filetype. If you want to ack a JPEG,
178190
# and say "ack foo whatever.jpg" it will do it for you.
@@ -307,8 +319,11 @@ sub build_regex {
307319

308320
$str = quotemeta( $str ) if $opt->{Q};
309321
if ( $opt->{w} ) {
310-
$str = "\\b$str" if $str =~ /^\w/;
311-
$str = "$str\\b" if $str =~ /\w$/;
322+
my $pristine_str = $str;
323+
324+
$str = "(?:$str)";
325+
$str = "\\b$str" if $pristine_str =~ /^\w/;
326+
$str = "$str\\b" if $pristine_str =~ /\w$/;
312327
}
313328

314329
my $regex_is_lc = $str eq lc $str;
@@ -803,14 +818,24 @@ sub resource_has_match {
803818
}
804819
}
805820
else {
806-
my $opt_v = $opt->{v};
807-
my $re = $opt->{regex};
808-
while ( <$fh> ) {
809-
if (/$re/o xor $opt_v) {
810-
$has_match = 1;
811-
last;
821+
my $re = $opt->{regex};
822+
if ( $opt->{v} ) {
823+
while ( <$fh> ) {
824+
if (!/$re/o) {
825+
$has_match = 1;
826+
last;
827+
}
812828
}
813829
}
830+
else {
831+
# XXX read in chunks
832+
# XXX only do this for certain file sizes?
833+
my $content = do {
834+
local $/;
835+
<$fh>;
836+
};
837+
$has_match = $content =~ /$re/og;
838+
}
814839
close $fh;
815840
}
816841

@@ -828,10 +853,18 @@ sub count_matches_in_resource {
828853
}
829854
}
830855
else {
831-
my $opt_v = $opt->{v};
832-
my $re = $opt->{regex};
833-
while ( <$fh> ) {
834-
++$nmatches if (/$re/o xor $opt_v);
856+
my $re = $opt->{regex};
857+
if ( $opt->{v} ) {
858+
while ( <$fh> ) {
859+
++$nmatches if (!/$re/o);
860+
}
861+
}
862+
else {
863+
my $content = do {
864+
local $/;
865+
<$fh>;
866+
};
867+
$nmatches =()= ($content =~ /$re/og);
835868
}
836869
close $fh;
837870
}
@@ -942,19 +975,16 @@ RESOURCES:
942975
last RESOURCES if defined($max_count) && $nmatches >= $max_count;
943976
}
944977
elsif ( $opt->{g} ) {
945-
my $is_match = ( $resource->name =~ /$opt->{regex}/o );
946-
if ( $opt->{v} ? !$is_match : $is_match ) {
947-
if ( $opt->{show_types} ) {
948-
show_types( $resource, $ors );
949-
}
950-
else {
951-
local $opt->{show_filename} = 0; # XXX Why is this local?
978+
if ( $opt->{show_types} ) {
979+
show_types( $resource, $ors );
980+
}
981+
else {
982+
local $opt->{show_filename} = 0; # XXX Why is this local?
952983

953-
print_line_with_options($opt, '', $resource->name, 0, $ors);
954-
}
955-
++$nmatches;
956-
last RESOURCES if defined($max_count) && $nmatches >= $max_count;
984+
print_line_with_options($opt, '', $resource->name, 0, $ors);
957985
}
986+
++$nmatches;
987+
last RESOURCES if defined($max_count) && $nmatches >= $max_count;
958988
}
959989
elsif ( $opt->{lines} ) {
960990
my $print_filename = $opt->{show_filename};
@@ -1670,6 +1700,27 @@ If you are not on Windows, you never need to use C<ACK_PAGER_COLOR>.
16701700
16711701
=back
16721702
1703+
=head1 AVAILABLE COLORS
1704+
1705+
F<ack> uses the colors available in Perl's L<Term::ANSIColor> module, which
1706+
provides the following listed values. Note that case does not matter when using
1707+
these values.
1708+
1709+
=head2 Foreground colors
1710+
1711+
black red green yellow blue magenta cyan white
1712+
1713+
bright_black bright_red bright_green bright_yellow
1714+
bright_blue bright_magenta bright_cyan bright_white
1715+
1716+
=head2 Background colors
1717+
1718+
on_black on_red on_green on_yellow
1719+
on_blue on_magenta on_cyan on_white
1720+
1721+
on_bright_black on_bright_red on_bright_green on_bright_yellow
1722+
on_bright_blue on_bright_magenta on_bright_cyan on_bright_white
1723+
16731724
=head1 ACK & OTHER TOOLS
16741725
16751726
=head2 Vim integration
@@ -2183,6 +2234,9 @@ L<https://github.com/petdance/ack2>
21832234
How appropriate to have I<ack>nowledgements!
21842235
21852236
Thanks to everyone who has contributed to ack in any way, including
2237+
Stephen Thirlwall,
2238+
Jonah Bishop,
2239+
Chris Rebert,
21862240
Denis Howe,
21872241
RaE<uacute>l GundE<iacute>n,
21882242
James McCoy,

0 commit comments

Comments
 (0)