Skip to content

Differentiate @world and non-@world sets in package field#2231

Open
hydrospherics wants to merge 20 commits intofastfetch-cli:devfrom
hydrospherics:emerge-set-diff
Open

Differentiate @world and non-@world sets in package field#2231
hydrospherics wants to merge 20 commits intofastfetch-cli:devfrom
hydrospherics:emerge-set-diff

Conversation

@hydrospherics
Copy link

@hydrospherics hydrospherics commented Mar 17, 2026

resolves #2230 and #2229 (gonna link them here anyway even if they're closed)

image basically implements set differentiation for emerge pkgs, splitting the single emerge count into emerge-world, and emerge-system.

detection reads /var/lib/portage/world for @world, and non-@world (a.k.a. emerge-system), and derives non-@world via total - world.

For Copilot:
1. ffStrbufCountC(content, '\n') computation is intentional since this is a fetch tool, not a dependency resolver
2. @system set pkg counting was previously present, but removed as per maintainer's advice because the code underneath is really fragile
3. non-@world pkgs and dependencies were consolidated to emerge-system because in Gentoo, you technically can't remove either since there'll be dependents, much like a system pkg itself. Who even pulls in Glibc intentionally?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Portage set differentiation to the Packages module by splitting the previous single emerge count into emerge-world, emerge-system, and emerge-deps, and exposes the new fields in formatting/JSON/schema.

Changes:

  • Implement Gentoo/Portage detection that derives world, system, and deps counts from Portage files and installed package DB.
  • Update Packages module output to show either combined emerge total or the three split counts depending on combined.
  • Extend format args, JSON output, and documented JSON schema to include emerge-world, emerge-system, and emerge-deps.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.

File Description
src/modules/packages/packages.c Prints split emerge counts when not combined; exposes new format args and JSON keys.
src/detection/packages/packages_linux.c Adds Portage parsing to compute world/system/deps counts.
src/detection/packages/packages.h Extends FFPackagesResult with new Portage split fields.
doc/json_schema.json Documents new packagesFormat placeholders for split emerge counts.

You can also share your feedback on Copilot code review. Take the survey.

@hydrospherics
Copy link
Author

hydrospherics commented Mar 17, 2026 via email

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Portage (@world/@system/deps) differentiation to the Packages module so emerge counts can be shown as either a single combined total or as split sub-counts.

Changes:

  • Split emerge detection into emerge-world, emerge-system, and emerge-deps, while retaining a combined emerge value.
  • Update module output/format args and JSON output to expose the new emerge sub-counts.
  • Update documentation schema text for the Packages formatting placeholders.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/modules/packages/packages.c Prints/exports split emerge counts when not combined; adds module args for new placeholders and JSON output keys.
src/detection/packages/packages_linux.c Implements Linux Portage set parsing for world/system and derives deps from total.
src/detection/packages/packages.h Extends FFPackagesResult with new emerge fields and adjusts struct layout around all.
doc/json_schema.json Updates the packagesFormat placeholder documentation to include the new emerge placeholders.

You can also share your feedback on Copilot code review. Take the survey.

@CarterLi
Copy link
Member

CarterLi commented Mar 17, 2026

What on earth does /var/lib/portage/world look like? Can you upload a sample file?

I checked the file in https://distrosea.com. I don't see a comment line. If it's a auto-generated file, I don't think it will contain comment or empty line.

@hydrospherics
Copy link
Author

What on earth does /var/lib/portage/world look like? Can you upload a sample file?

➜  anthony@asta ~ cat /var/lib/portage/world
app-admin/doas
app-arch/7zip
app-arch/unrar
app-containers/podman
app-editors/nano
app-editors/vim
app-eselect/eselect-repository
app-misc/fastfetch
app-misc/jq
app-misc/sl
app-portage/eix
app-portage/genlop
app-portage/gentoolkit
app-shells/nushell
app-text/ghostscript-gpl
app-text/mupdf
dev-dotnet/dotnet-sdk-bin
dev-lang/zig
dev-util/android-tools
dev-util/pkgcheck
dev-util/pkgdev
games-misc/cowsay
games-misc/nyancat
gnome-base/dconf-editor
gnome-base/gnome-light
gnome-extra/gnome-browser-connector
gnome-extra/gnome-shell-extensions
gnome-extra/gnome-tweaks
llvm-core/lld
media-fonts/noto
media-fonts/noto-cjk
media-gfx/imagemagick
media-gfx/iscan
media-gfx/sane-backends
media-libs/libsdl2
media-libs/libv4l
media-libs/tiff
media-video/celluloid
media-video/ffmpeg
net-dns/bind-tools
net-misc/networkmanager
net-misc/whois
net-misc/yt-dlp
net-p2p/transmission
net-print/cups
net-print/cups-filters
net-print/cups-meta
net-print/epson-inkjet-printer-escpr
net-print/libcupsfilters
net-wireless/wireless-regdb
sys-apps/baobab
sys-apps/cpuid
sys-apps/mlocate
sys-apps/pciutils
sys-apps/qdiskinfo
sys-apps/ripgrep
sys-apps/systemd
sys-auth/rtkit
sys-block/io-scheduler-udev-rules
sys-boot/efibootmgr
sys-boot/gnu-efi
sys-boot/grub
sys-boot/plymouth
sys-firmware/intel-microcode
sys-firmware/sof-firmware
sys-fs/btrfs-progs
sys-fs/dosfstools
sys-fs/ntfs3g
sys-kernel/git-sources
sys-kernel/installkernel
sys-kernel/linux-firmware
sys-kernel/linux-headers
sys-libs/glibc
sys-power/thermald
www-client/brave-browser
www-client/lynx
x11-terms/ptyxis

it is basically a file that lists out the packages that I explicitly added through emerge.

@CarterLi
Copy link
Member

@hydrospherics Why do you think it may contain empty or comment lines?

@hydrospherics
Copy link
Author

@hydrospherics Why do you think it may contain empty or comment lines?

it usually doesnt (portage handles it fine), but copilot suggested that I harden the parsing anyway.

maybe I guess.. some people edit their world file manually?

@CarterLi
Copy link
Member

CarterLi commented Mar 17, 2026

People can even run rm -rf --no-preserve-root /. I don't think fastfetch wants to support the case.

Counting the number of \n of the file should be ok.

@CarterLi
Copy link
Member

The code of counting @system packages seems over complicated and vulnerable to me. Can we just counting @world and non-@world?

@hydrospherics
Copy link
Author

People can even run rm -rf --no-preserve-root /. I don't think fastfetch wants to support the case.

Counting the number of \n of the file should be ok.

true, I do that alot for some reason.. but AI is AI, it wants to handhold in some way.

@hydrospherics
Copy link
Author

hydrospherics commented Mar 17, 2026

The code of counting @system packages seems over complicated and vulnerable to me. Can we just counting @world and non-@world?

I see, so I guess I'll go rm counting the @system set and just resort to smth like:
emerge-world, emerge-non-world (/var/db/pkg/*/* count minus @world count), and emerge-all for all combined

hell, maybe even count non-world as emerge-system instead since you can't really remove them unless you unmerge forcefully.

Removed the addition of 'emerge-all' count to the JSON object.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve Gentoo/Portage package reporting by splitting the single emerge count into separate set-based counters, aligning Portage reporting closer to how other ecosystems (e.g., Nix) are differentiated.

Changes:

  • Replaced the single emerge counter with emerge-world and emerge-system counters, plus an emerge-all aggregate for formatting.
  • Updated Linux package detection to read /var/lib/portage/world and derive a second count from the total installed set.
  • Updated the packages module’s formatting args and JSON schema documentation to reflect the new placeholders.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/modules/packages/packages.c Updates printing/format args to expose emerge-world, emerge-system, and emerge-all.
src/detection/packages/packages_linux.c Adds a Portage-specific counting routine that reads the world file and splits totals.
src/detection/packages/packages.h Replaces emerge field with emergeWorld/emergeSystem in the result struct.
doc/json_schema.json Updates the packagesFormat description to document the new format tokens.

You can also share your feedback on Copilot code review. Take the survey.

CarterLi and others added 2 commits March 18, 2026 08:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@CarterLi
Copy link
Member

@ceamac What's your opinion?

TLDR: This PR splits emerge packages count into emerge-world and emerge-system (actually non-world, i.e. @all - @world). It used to fetch @system and @dep packages count but was removed due to the complexity and vulnerability of the code.

@hydrospherics hydrospherics changed the title Differentiate @world and @system sets in package count schema Differentiate @world and non-@world sets in package field Mar 18, 2026
@hydrospherics
Copy link
Author

force pushed to amend the commit message from the merge new changes thing (I did that on web).

Also, we could consider aliasing emerge to emerge-all so we don't break the current configs people have that use emerge.

@CarterLi
Copy link
Member

LGTM, but I don't know if emerge-system causes confusion to other gentoo users.

@ceamac
Copy link
Contributor

ceamac commented Mar 19, 2026

@ceamac What's your opinion?

TLDR: This PR splits emerge packages count into emerge-world and emerge-system (actually non-world, i.e. @all - @world). It used to fetch @system and @dep packages count but was removed due to the complexity and vulnerability of the code.

Yes, @system is particularly hard to count because it depends on the current profile, profiles can include other profiles, and users can even use custom profiles, it would not be straight forward to determine which packages it contains.

Most distributions keep track of which packages are manually installed and which are dependencies only, so they can be cleaned when no longer needed (see apt-mark in Debian or pacman --asdeps in Arch and so on). I don't know if this is a metric that should be added to some or all distributions, that is not for me to decide. In Gentoo this count is not too easy to get accurately.

Other than the @world set we also have custom sets, which also contain packages that the user has installed explictly, so they will not be autocleaned. You can find them in /var/lib/portage/world_sets with the contents in etc/portage/sets. For example in my case (I assume this is a popular one)

$ cat /var/lib/portage/world_sets
@esteam

Where /etc/portage/sets/esteam has the same format as the world file, but being in /etc it is expected to be edited manually, so it can contain comments and empty lines (esteam in particular is managed by games-util/esteam from the steam overlay, but it still containes comments).

Some people have more manually defined sets, so counting only the packages from the world file does not return the whole picture. I would say the world file is a pretty good approximation, it covers most uses, but not all.

I will look over the implementation in the weekend, now I only read the discussion.

@hydrospherics
Copy link
Author

Yes, @system is particularly hard to count because it depends on the current profile, profiles can include other profiles, and users can even use custom profiles, it would not be straight forward to determine which packages it contains.

Most distributions keep track of which packages are manually installed and which are dependencies only, so they can be cleaned when no longer needed (see apt-mark in Debian or pacman --asdeps in Arch and so on). I don't know if this is a metric that should be added to some or all distributions, that is not for me to decide. In Gentoo this count is not too easy to get accurately.

Other than the @world set we also have custom sets, which also contain packages that the user has installed explictly, so they will not be autocleaned. You can find them in /var/lib/portage/world_sets with the contents in etc/portage/sets. For example in my case (I assume this is a popular one)

$ cat /var/lib/portage/world_sets
@esteam

Where /etc/portage/sets/esteam has the same format as the world file, but being in /etc it is expected to be edited manually, so it can contain comments and empty lines (esteam in particular is managed by games-util/esteam from the steam overlay, but it still containes comments).

Some people have more manually defined sets, so counting only the packages from the world file does not return the whole picture. I would say the world file is a pretty good approximation, it covers most uses, but not all.

I will look over the implementation in the weekend, now I only read the discussion.

Yeah, looking back I have no idea what I was thinking trying to count @system, I was using plain asterisks to count the packages there, which was.. vulnerable, to say.

As for world_sets, I'd suggest counting them under emerge-world if we ever get to it. Merging them into a separate counter would just pollute the display for users with a lot of custom sets, and semantically they're still explicitly installed packages anyway.

Anyways, thanks for dropping by for now though.

@hydrospherics
Copy link
Author

LGTM, but I don't know if emerge-system causes confusion to other gentoo users.

Ahh, I didn't mean that it would cause confusion, it's just that, some people might not have their configs up ahead so yea.

Your call though.

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.

[FEAT] Differentiate emerge package counts by set (@world, @system, deps)

4 participants