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

gnu compatiblity fix for case sensitivity handling of suffixes #86

Closed
wants to merge 4 commits into from

Conversation

matrixhead
Copy link
Contributor

hi, this a pr that tries to fix to this issue.

Copy link
Contributor

@tavianator tavianator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! See #69 for an older attempt at this.

I like this approach, just have a couple issues with it that I noted. With those fixed I think this is good to go.

@@ -228,10 +255,7 @@ pub struct LsColors {
/// Whether Indicator::RegularFile falls back to Indicator::Normal
/// (see <https://github.com/sharkdp/lscolors/issues/48#issuecomment-1582830387>)
file_normal_fallback: bool,

// Note: you might expect to see a `HashMap` for `suffix_mapping` as well, but we need to
// preserve the exact order of the mapping in order to be consistent with `ls`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to this? The new implementation uses only a HashMap so I don't see how it can distinguish between *.gz=01;33:*.tar.gz=01;31: and *.tar.gz=01;31:*.gz=01;33:, which should behave differently. (Perhaps we are missing a test if this wasn't caught.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was looking for the longest match, that's my bad, I'll fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I fixed this, fixed the test also

src/lib.rs Outdated
fn push(&mut self, suffix: FileNameSuffix, style: Option<Style>) {
let normalized_suffix = suffix.to_ascii_lowercase();
// decides whether new mapping and it's varaints should be treated as case-sensitive
let is_case_sensitive = self.mappings.iter().any(|(m_suffix, m_style)| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to avoid $O(n^2)$ complexity here, since some people have pretty large $LS_COLORS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay let me try 😀

Copy link
Contributor Author

@matrixhead matrixhead Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to reduce the complexity, now when adding a single entry it doesn't compare with each entry just with its variants, which I guess in real world situations should be tiny compared to $LS_COLORS.
now case sensitivities are solved in a single pass after all the entries are added.

@sharkdp
Copy link
Owner

sharkdp commented Jul 16, 2024

If I understand correctly, we agree to close this in favor of #87. Let me know if that's not true.

@sharkdp sharkdp closed this Jul 16, 2024
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 this pull request may close these issues.

3 participants