Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add option to disable reading file content to guess filetype #147

Closed
kcwu opened this Issue · 4 comments

2 participants

@kcwu

Suggest to add option to disable reading file header to guess filetype.
This should disable

  • test binary file
  • shebang line

Read files from NFS is slow, so I would like search files only based on filename.

@kcwu

Alternative solution:
Read file content only if user specify file type binary,text,ruby,perl,php,python,*sh,xml,etc.

For example, it's unnecessary to read file content for ack --cpp.

@petdance
Owner

kcwu: Thanks, that makes a lot of sense.

@kcwu
diff --git a/Ack.pm b/Ack.pm
index 3cf01dc..609a347 100644
--- a/Ack.pm
+++ b/Ack.pm
@@ -519,6 +519,7 @@ sub filetypes {
     # At this point, we can't tell from just the name.  Now we have to
     # open it and look inside.

+    return unless grep defined $type_wanted{$_}, qw/binary shell xml ruby perl php python/, TEXT;
     return unless -e $filename;
     # From Elliot Shank:
     #     I can't see any reason that -r would fail on these-- the ACLs look
@@ -534,6 +535,7 @@ sub filetypes {
     }

     return 'binary' if -B $filename;
+    return (TEXT) unless grep defined $type_wanted{$_}, qw/shell xml ruby perl php python/;

     # If there's no extension, or we don't recognize it, check the shebang line
     my $fh;
@petdance
Owner

This is much smarter in ack 2.

@petdance petdance closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.