Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scandir.c: traverse in consistent order #942

Closed
wants to merge 1 commit into from

Commits on Jul 19, 2016

  1. scandir.c: traverse in consistent order

    `readdir()` returns directories in an implementation-dependent order.
    In practice it's based on a hash of the filenames, aka random:
    
        $ ls
        01.txt  02.txt  03.txt
    
        $ ag -l hello
        02.txt
        03.txt
        01.txt
    
    This commit calls `qsort()` on the output of `readdir()`.
    Now, results are almost always sorted alphabetically:
    
        $ ag -l hello
        01.txt
        02.txt
        03.txt
    
    This doesn't guarantee 100% sorted order - worker threads will still
    race each other - but 99% of the time it will be sorted completely.
    
    This means you can largely expect to get the same `ag` output on
    different OSes or different checkouts. Plus, if you're running a slow
    `ag` command and see the "foo" directory:
    
        $ ls
        ack  bar  foo  quux
    
        $ ag hello
        foo/hello.txt
        1:hello
    
        ...
    
    you can be sure there are no matches in "ack" and "bar".
    
    This commit partially fixes ggreer#107.
    bmalehorn committed Jul 19, 2016
    Configuration menu
    Copy the full SHA
    3e2b870 View commit details
    Browse the repository at this point in the history