Skip to content

Get tree entries per type. [Old: Allow sorting of tree entries] #220

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

Closed
Patrick-Beuks opened this issue Apr 24, 2024 · 5 comments
Closed

Comments

@Patrick-Beuks
Copy link
Contributor

To get entries of a tree this library uses cat-file.

From what I can tell this returns the tree items based on the code point of the file name.

The outcome of this is that trees/commitRefs are combined with blobs.

My suggestion would be to add an additional parameter (either an enum or const) that allows you to pick a sorting algorithm that would be applied to the entries before they are returned.

I am willing to make an implementations for this, but there are a multitude of ways to sort a directory and I would need to know that if this should be implemented how far it should go.

Some sorting suggestions

  • Only separate tree/commitRef from the blobs and keep sorting based on code point
  • Sort but ignore case
  • Use natural sorting
  • Use case independent sorting
  • Ignore leading dots while sorting
  • Allow sorting using the intl library (this library does need to know what locale to use while sorting, you might take it from the system, or you allow it to set it somehow or allow you to pass a collator parameter instead of the additional parameter
@lyrixx
Copy link
Member

lyrixx commented Apr 26, 2024

Hello, the sort could be done in userland? Is it really useful to put this in the core?

@Patrick-Beuks
Copy link
Contributor Author

Patrick-Beuks commented Apr 26, 2024

The return of this function contains multiple object types, while the key is just the name of the tree/commitRef/blob it does not allow for an easy sort on just that name, something you probably want if you want to use this library to show the tree.

So at least an option to split blobs from the rest would be useful.

As you probably don't want to change the return type to show this split, you still return the names as key and then the object so you are still not able to sort on that in userland as it still would combine the two.

A different solution that I just came up with:
Add another array that has the entries by type and also initialize this when the tree initializes as you have the type available here. and then allow you to ask for the entries by type, or add it as an additional parameter to the entries function.

This would allow you to sort them based on the key in userland and with the spread operator combine them into a single array very easily

@Patrick-Beuks
Copy link
Contributor Author

I liked the second idea more.

I wanted to try this one out and made a draft PR of the implementation.

@Patrick-Beuks Patrick-Beuks changed the title Allow sorting of tree entries Get tree entries per type. ~~Allow sorting of tree entries~~ May 6, 2024
@Patrick-Beuks Patrick-Beuks changed the title Get tree entries per type. ~~Allow sorting of tree entries~~ Get tree entries per type. [Old: Allow sorting of tree entries] May 6, 2024
@Patrick-Beuks
Copy link
Contributor Author

I have been using my implementation for a while now and it allows for the functionality in userland without the hassle I was running into before

@lyrixx
Copy link
Member

lyrixx commented May 6, 2024

Fixed by #221

@lyrixx lyrixx closed this as completed May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants