beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 138 forks source link

Files from recursive file search should always be sorted #550

Closed rillig closed 4 years ago

rillig commented 9 years ago

When I run ack return src, the files from the src 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.

Example: When running ack searchTerm /usr/include include src checks, the files should be displayed in the following order:

  1. all files from /usr/include, sorted alphabetically
  2. all files from include, sorted alphabetically
  3. all files from src, sorted alphabetically
  4. all files from checks, sorted alphabetically
hoelzro commented 9 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.

petdance commented 9 years ago

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.

rillig commented 9 years ago

To prevent a misunderstanding:

petdance commented 9 years ago

You can get the files sorted with --sort-files, but then you'll also get your starting directories sorted as well.

epa commented 9 years ago

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.