ignore binary file is not enabled by default and can't be turned on?

193 views
Skip to first unread message

Yuanle

unread,
Nov 8, 2011, 4:08:23 AM11/8/11
to ack dev/users
I can't ask ack to ignore binary files, in this case, images.

Tested in debian 6.0, ack packaged version ack-grep 1.92 and latest
binary version 1.96.
the log below is tested using latest standalone version.

Maybe I'm doing something wrong, but I just can't figure it out.

Here is the console log of the problem:
~/html/yxy-business $ file src/collections/动物/斑马家族2.jpg
src/collections/动物/斑马家族2.jpg: JPEG image data, EXIF standard
~/html/yxy-business $ perl -e 'if (-B "src/collections/动物/斑马家族2.jpg")
{print "binary\n";} else {print "no\n";}'
binary
~/html/yxy-business $ ack --version
ack 1.96
Running under Perl 5.10.1 at /usr/bin/perl

Copyright 2005-2011 Andy Lester.

This program is free software. You may modify or distribute it
under the terms of the Artistic License v2.0.
~/html/yxy-business $ ack '(TODO[^s]|FIXME|BUG)' src/collections/动物/*
Binary file src/collections/动物/斑马家族2.jpg matches
~/html/yxy-business $ ack --nobinary '(TODO[^s]|FIXME|BUG)' src/
collections/动物/*
Binary file src/collections/动物/斑马家族2.jpg matches
~/html/yxy-business $

Andy Lester

unread,
Nov 8, 2011, 9:49:31 AM11/8/11
to ack-...@googlegroups.com

On Nov 8, 2011, at 3:08 AM, Yuanle wrote:

I can't ask ack to ignore binary files, in this case, images.

Ack ignores any file type it doesn't recognize.  The only reasons it would NOT ignore JPEGs would be because either 1) someone had added .jpg as a file type, or 2) you're calling ack with the -a option.

Is ack an alias to "ack -a"?  Or do you have an ACK_OPTIONS set to "-a"?

Try running ack with --noenv and see what happens.

xoa

Rob Hoelz

unread,
Nov 8, 2011, 10:07:20 AM11/8/11
to ack-...@googlegroups.com
On Tue, 8 Nov 2011 01:08:23 -0800 (PST)
Yuanle <syl...@gmail.com> wrote:

> I can't ask ack to ignore binary files, in this case, images.
>
> Tested in debian 6.0, ack packaged version ack-grep 1.92 and latest
> binary version 1.96.
> the log below is tested using latest standalone version.
>
> Maybe I'm doing something wrong, but I just can't figure it out.
>
> Here is the console log of the problem:
> ~/html/yxy-business $ file src/collections/动物/斑马家族2.jpg
> src/collections/动物/斑马家族2.jpg: JPEG image data, EXIF standard
> ~/html/yxy-business $ perl -e 'if (-B "src/collections/动物/
> 斑马家族2.jpg") {print "binary\n";} else {print "no\n";}'
> binary
> ~/html/yxy-business $ ack --version
> ack 1.96
> Running under Perl 5.10.1 at /usr/bin/perl
>
> Copyright 2005-2011 Andy Lester.
>
> This program is free software. You may modify or distribute it
> under the terms of the Artistic License v2.0.

> ~/html/yxy-business $ ack '(TODO[^s]|FIXME|BUG)' src/collections/


> 动物/* Binary file src/collections/动物/斑马家族2.jpg matches
> ~/html/yxy-business $ ack --nobinary '(TODO[^s]|FIXME|BUG)' src/
> collections/动物/*
> Binary file src/collections/动物/斑马家族2.jpg matches
> ~/html/yxy-business $
>

It seems you're doing the following:

ack '(TODO[^s]|FIXME|BUG)' src/collections/动物/*

Your shell will expand the wildcard to include 斑马家族2.jpg, and ack
*always* searches regular files that are provided directly on the
command line.

-Rob

Andy Lester

unread,
Nov 8, 2011, 10:31:19 AM11/8/11
to ack-...@googlegroups.com

On Nov 8, 2011, at 9:07 AM, Rob Hoelz wrote:

ack '(TODO[^s]|FIXME|BUG)' src/collections/动物/*

Your shell will expand the wildcard to include 斑马家族2.jpg, and ack
*always* searches regular files that are provided directly on the
command line.

Rob's answer here is correct.  I didn't notice the * at the end of the path.  Files specified on the command line are always checked, and directories specified on the command line are never skipped, even if you have options telling ack to do so.  The general rule is to let ack do as much on its own as it can.

Thanks, Rob!

Packy Anderson

unread,
Nov 8, 2011, 10:54:40 AM11/8/11
to ack-...@googlegroups.com
So, the simple answer is to just use


ack '(TODO[^s]|FIXME|BUG)' src/collections/动物/

This will restrict ack to just searching that directory, but will let ack decide which files are code and which are not.

Or you could just use 


ack '(TODO[^s]|FIXME|BUG)'

and let ack search the whole source tree.

2011/11/8 Andy Lester <an...@petdance.com>

--
You received this message because you are subscribed to the Google Groups "ack dev/users" group.
To post to this group, send email to ack-...@googlegroups.com.
To unsubscribe from this group, send email to ack-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ack-users?hl=en.



--
Packy Anderson

Email:  PackyA...@gmail.com
GVoice: (646) 833-8832
Reply all
Reply to author
Forward
0 new messages