Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 3 contributors
Commits on Feb 02, 2012
@suan suan Make ack aware of "lock" files e418d6f
Suan-Aik Yeo Add lock type in mappings 4a098ad
Commits on May 04, 2012
@suan suan Merge branch 'master' of https://github.com/petdance/ack ecc10b0
@willert willert Allow files without an extension to be recognized as a distinct type.…
… Keep old behavior unless --type-allow-empty is explicitly specified. Added tests and help text for this change.
38316d3
View
15 Ack.pm
@@ -381,6 +381,7 @@ i.e. into %mappings, etc.
sub def_types_from_ARGV {
my @typedef;
+ my $allow_empty_types;
my $parser = Getopt::Long::Parser->new();
# pass_through => leave unrecognized command line arguments alone
@@ -389,10 +390,11 @@ sub def_types_from_ARGV {
$parser->getoptions(
'type-set=s' => sub { shift; push @typedef, ['c', shift] },
'type-add=s' => sub { shift; push @typedef, ['a', shift] },
+ 'type-allow-empty' => \$allow_empty_types,
) or App::Ack::die( 'See ack --help or ack --man for options.' );
for my $td (@typedef) {
- my ($type, $ext) = split /=/, $td->[1];
+ my ($type, $ext) = split /=/, $td->[1], -1;
if ( $td->[0] eq 'c' ) {
# type-set
@@ -415,9 +417,12 @@ sub def_types_from_ARGV {
unless exists $mappings{$type};
}
- my @exts = split /,/, $ext;
+ my @exts = length($ext) ? split /,/, $ext, -1 : ''; # split returns undef on empty string
s/^\.// for @exts;
+ # restore old behavior of ignoring empty typedefs unless explicitly asked to do otherwise
+ @exts = grep{ $_ } @exts unless $allow_empty_types;
+
if ( !exists $mappings{$type} || ref($mappings{$type}) eq 'ARRAY' ) {
push @{$mappings{$type}}, @exts;
for my $e ( @exts ) {
@@ -508,6 +513,10 @@ sub filetypes {
if ( $filename =~ m{\.([^\.$dir_sep_chars]+)$}o ) {
my $ref = $types{lc $1};
return (@{$ref},TEXT) if $ref;
+ } elsif ( exists $types{''} ) {
+ # files without extensions could have an user defined type
+ my $ref = $types{''};
+ return (@{$ref},TEXT) if $ref;
}
# At this point, we can't tell from just the name. Now we have to
@@ -854,6 +863,8 @@ File inclusion/exclusion:
--type-add TYPE=.EXTENSION[,.EXT2[,...]]
Files with the given EXTENSION(s) are recognized as
being of (the existing) type TYPE
+ --type-allow-empty Allow files without an extension to be recognized as
+ a distinct type.
--[no]follow Follow symlinks. Default is off.
View
17 ack
@@ -1249,6 +1249,7 @@ BEGIN {
js => [qw( js )],
jsp => [qw( jsp jspx jhtm jhtml )],
lisp => [qw( lisp lsp )],
+ lock => q{lockfiles},
lua => [qw( lua )],
make => q{Makefiles (including *.mk and *.mak)},
mason => [qw( mas mhtml mpl mtxt )],
@@ -1508,6 +1509,7 @@ sub get_command_line_options {
sub def_types_from_ARGV {
my @typedef;
+ my $allow_empty_types;
my $parser = Getopt::Long::Parser->new();
# pass_through => leave unrecognized command line arguments alone
@@ -1516,10 +1518,11 @@ sub def_types_from_ARGV {
$parser->getoptions(
'type-set=s' => sub { shift; push @typedef, ['c', shift] },
'type-add=s' => sub { shift; push @typedef, ['a', shift] },
+ 'type-allow-empty' => \$allow_empty_types,
) or App::Ack::die( 'See ack --help or ack --man for options.' );
for my $td (@typedef) {
- my ($type, $ext) = split /=/, $td->[1];
+ my ($type, $ext) = split /=/, $td->[1], -1;
if ( $td->[0] eq 'c' ) {
# type-set
@@ -1542,9 +1545,12 @@ sub def_types_from_ARGV {
unless exists $mappings{$type};
}
- my @exts = split /,/, $ext;
+ my @exts = length($ext) ? split /,/, $ext, -1 : ''; # split returns undef on empty string
s/^\.// for @exts;
+ # restore old behavior of ignoring empty typedefs unless explicitly asked to do otherwise
+ @exts = grep{ $_ } @exts unless $allow_empty_types;
+
if ( !exists $mappings{$type} || ref($mappings{$type}) eq 'ARRAY' ) {
push @{$mappings{$type}}, @exts;
for my $e ( @exts ) {
@@ -1598,6 +1604,7 @@ sub filetypes {
return 'skipped' unless is_searchable( $basename );
my $lc_basename = lc $basename;
+ return ('lock',TEXT) if $lc_basename eq 'lock';
return ('make',TEXT) if $lc_basename eq 'makefile' || $lc_basename eq 'gnumakefile';
return ('rake','ruby',TEXT) if $lc_basename eq 'rakefile';
@@ -1605,6 +1612,10 @@ sub filetypes {
if ( $filename =~ m{\.([^\.$dir_sep_chars]+)$}o ) {
my $ref = $types{lc $1};
return (@{$ref},TEXT) if $ref;
+ } elsif ( exists $types{''} ) {
+ # files without extensions could have an user defined type
+ my $ref = $types{''};
+ return (@{$ref},TEXT) if $ref;
}
# At this point, we can't tell from just the name. Now we have to
@@ -1901,6 +1912,8 @@ File inclusion/exclusion:
--type-add TYPE=.EXTENSION[,.EXT2[,...]]
Files with the given EXTENSION(s) are recognized as
being of (the existing) type TYPE
+ --type-allow-empty Allow files without an extension to be recognized as
+ a distinct type.
--[no]follow Follow symlinks. Default is off.
View
1  t/ack-text.t 100644 → 100755
@@ -48,6 +48,7 @@ ACK_F_TEXT: {
t/swamp/Makefile
t/swamp/Makefile.PL
t/swamp/javascript.js
+ t/swamp/no-extension
t/swamp/not-an-#emacs-workfile#
t/swamp/notaMakefile
t/swamp/notaRakefile
View
20 t/ack-type.t 100644 → 100755
@@ -3,7 +3,7 @@
use warnings;
use strict;
-use Test::More tests => 74;
+use Test::More tests => 82;
use lib 't';
use Util qw( sets_match );
@@ -37,6 +37,15 @@ my $bar = [qw(
t/swamp/file.bar
)];
+my $none = [
+ 't/swamp/0',
+ 't/swamp/no-extension',
+ 't/swamp/not-an-#emacs-workfile#',
+ 't/swamp/notaMakefile',
+ 't/swamp/notaRakefile',
+ 't/swamp/perl-without-extension',
+];
+
my $xml = [qw(
t/etc/buttonhook.rss.xxx
t/etc/buttonhook.xml.xxx
@@ -109,6 +118,15 @@ check_with( '--type-add xml=.foo,.bar --xml', $foo_bar_xml );
# check that --type-set redefines
check_with( '--type-set cc=.foo --cc', $foo );
+# check --type-set with empty EXT
+check_with( '--type-set empty= --type empty --no-recurse', [] );
+check_with( '--type-set empty= --type empty --no-recurse --type-allow-empty', $none );
+
+# check --type-add with empty EXT
+check_with( '--type-add cc= --cc --no-recurse', $cc_hh );
+check_with( '--type-add cc= --cc --no-recurse --type-allow-empty', [ sort @$cc_hh, @$none ]);
+
+
# check that builtin types cannot be changed
BUILTIN: {
my @builtins = qw( make skipped text binary );
View
1  t/swamp/no-extension
@@ -0,0 +1 @@
+nothing to see here, move along

No commit comments for this range

Something went wrong with that request. Please try again.