xbps icon indicating copy to clipboard operation
xbps copied to clipboard

Add orderby flag.

Open ericonr opened this issue 5 years ago • 6 comments

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 :)

ericonr avatar Apr 29 '20 17:04 ericonr

@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.

ericonr avatar Apr 30 '20 01:04 ericonr

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 :)

ericonr avatar May 01 '20 04:05 ericonr

@Duncaen ping. I think this is in a good state now. Only does sorting, no arbitrary formatting. That will be a bit more involved.

ericonr avatar Jun 17 '20 03:06 ericonr

I would prefer to have implemented (to implement?) --format, and make use of sort -k

Chocimier avatar Sep 16 '21 16:09 Chocimier

I think for the flag name, --order-by reads better than --orderby.

camoz avatar Dec 28 '21 06:12 camoz

Hi, all. is this ready to be merged?

veksha avatar Jul 11 '22 09:07 veksha