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

--reverse does not reverse in the case of a tie #863

Open
lunik1 opened this issue May 1, 2021 · 1 comment · May be fixed by #869
Open

--reverse does not reverse in the case of a tie #863

lunik1 opened this issue May 1, 2021 · 1 comment · May be fixed by #869

Comments

@lunik1
Copy link

lunik1 commented May 1, 2021

Exa version v0.10.1 [+git], NixOS.

If two items are the same in the sort order, --reverse will not reverse their order. The easiest demonstration is to create three files at the same time

touch file1 file2 file3

and sort by newest

exa -snew
file1  file3  file2

This is "directory order" (ls -U) so it may be different from this example. If we try to reverse this order...

exa -r -snew
file1  file3  file2

we still get the directory order! think this behaviour is surprising, and can be particularity vexacious when there are only some ties.

In ls (GNU, busybox, and toybox at least) the tie appears to be broken by filename:

ls -t
file1 file2 file3

and

ls -rt
file3 file2 file1

to me this is sensible behaviour, but in any case I think the --reverse flag should always produce the opposite order of files within a directory to the same command without the --reverse flag.

@ariasuni
Copy link
Collaborator

ariasuni commented May 5, 2021

I found the problem: turns out that sometimes files are sorted two times.

So the sort is stable which means it doesn’t change the order of equal elements. In your case:

Sort 1:    file1 file3 file2 (the elements are all equal so the original, filesystem order is kept)
Reverse 1: file2 file3 file1
Sort 2:    file2 file3 file1 (the elements are all equal so again the order is unchanged)
Reverse 2: file1 file3 file2

In most case, you wouldn’t notice it since the element would be sorted then reversed, but in this case the sort does nothing, so it’s noticeable.

@ariasuni ariasuni linked a pull request May 11, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants