Closed rillig closed 4 years ago
@rillig The way ack find files to search (regarding order, and ignoring things like filters) is this:
Get list of files from current directory
If --sort-files is on, sort that list in lexicographical order
For each file in that list:
If the file is a directory, recurse into it
Otherwise, search its contents
I don't think @petdance will want to change this behavior, mainly since it would affect and surprise all of the users who understand ack to behave as specified above.
I don't know. It's an interesting idea. I can see why you'd want to specify a certain order for things on the command line.
To prevent a misunderstanding:
You can get the files sorted with --sort-files
, but then you'll also get your starting directories sorted as well.
Sorting the files is probably more useful than the current behaviour, but perhaps marginally slower (on rotating storage at least). However it might not be good to commit to sorted filenames as documented behaviour, since it precludes optimizations like scanning the tiny files first and leaving huge ones for later. I guess --sort-files-within-directory
as an explicit option would work.
When I run
ack return src
, the files from thesrc
directory are listed in apparently random order. This order can be changed by passing the--sort-files
option. But then, all files are sorted, no matter in which order they were given on the command line.--sort-files
should only affect the files that were given explicitly on the command line.Example: When running
ack searchTerm /usr/include include src checks
, the files should be displayed in the following order:/usr/include
, sorted alphabeticallyinclude
, sorted alphabeticallysrc
, sorted alphabeticallychecks
, sorted alphabetically