xbps
xbps copied to clipboard
Add orderby flag.
Initial implementation, only works in conjunction with the -m switch,
for now.
Will fix #163
This is just a very rough start, but it had a sorted output :)
A few TODO comments around, too. And of_free isn't run if the key doesn't exist, it just exits.
I wasn't very sure of how proplib stuff worked, so I ended up duplicating all the strings.
Unless I implement an orderby function for each kind of listing, we'd need to make some changes to listing functions. I was thinking of adding a "mode" parameter in a parameter struct, perhaps. Something like:
- Unbuffered mode: the current one, just prints the packages to stdout.
- Formatted mode: to fix #241 (could be implemented together with unbuffered)
- Sorting/post processing mode: stores some strings or the dictionary obj themselves, then sorts/does something with them afterwards, and then outputs them using the format functions.
Taking all feedback, my hosted C needs improvement :)
@Duncaen I have to do some revision and I'd like to write some tests for it first, but I think it's in good shape. The way I structured the code means that all pointers are held in memory before any printing is done (in my system this meant 2MB of memory concumption, I don't know how high it can get), so it's something to be aware of.
However, if you think this is sound and something we should stick to (and also that the energy spent is worth it), I would be interested in rewriting most printing modes to go through the functions I wrote. This would allow us to use arbitrary ordering in all of those that list packages, and would go together with implementing the formatting stuff. We could even have "default" formatting modes to keep the tool compatible with scripts people wrote.
Performance impact, not the best testing ever. Memory usage measurement done through valgrind.
xbps-query -m --orderby installed_size
- on glibc, with 114 manually installed packages, on an SSD, it takes around 16ms to run and uses up 2MiB of memory.
- on musl, with 2400 manually installed packages, on an HD, it takes around 500ms to run with caches dropped, 150ms on the second run, and up to 11MiB of memory.
Sounds ok to me, shouldn't be a bottleneck. Also, it's pretty much the same amount of memory and time that default xbps-query uses, without sorting. So I think it's ok :)
@Duncaen ping. I think this is in a good state now. Only does sorting, no arbitrary formatting. That will be a bit more involved.
I would prefer to have implemented (to implement?) --format, and make use of sort -k
I think for the flag name, --order-by reads better than --orderby.
Hi, all. is this ready to be merged?