Handy commands to clean up old ~arch-only packages

Here’s a bunch of handy commands that I’ve conceived to semi-automatically remove old versions of packages that do not have stable keywords (and therefore are not subject to post-stabilization cleanups that I do normally).

Requirements

The snippets below require the following packages:

  • app-portage/mgorny-dev-scripts
  • dev-util/pkgcheck
  • dev-util/pkgdev

They should be run in top directory of a ::gentoo checkout, ideally with no other changes queued.

Remove redundant versions

First, a pipeline that finds all packages without stable amd64 keywords (note: this is making an assumption that there are no packages that are stable only on some other architecture), then scans these packages for redundant versions and removes them. The example command operates on dev-python/*:

pkgcheck scan 'dev-python/*' -c UnstableOnlyCheck -a amd64 \
    -R FormatReporter --format '{category}/{package}' |
  sort -u |
  xargs pkgcheck scan -c RedundantVersionCheck \
    -R FormatReporter --format \
    '{category}/{package}/{package}-{version}.ebuild' |
  xargs git rm

Check for broken revdeps

The next step is to check for broken revdeps. Start with:

rdep-fetch-cache
check-revdep $(
  git diff --name-only --cached | cut -d'/' -f1-2 | sort -u
)

Use git restore -WS ... to restore versions as necessary and repeat until it comes out clean.

Check for stale files

Finally, iterate over packages with files/ to check for stale patches:

(
  for x in $(
    git diff --name-only --cached | cut -d'/' -f1-2 | sort -u
  ); do
    [[ -d ${x}/files ]] && ( cd ${x}; bash )
  done
)

This will start bash inside every cleaned up package (note: I’m assuming that there are no other changes in the repo) that has a files/ directory. Use a quick grep followed by FILESDIR lookup:

grep FILES *.ebuild
ls files/

Remove the files that are no longer referenced.

Commit the removals

for x in $(
  git diff --name-only --cached | cut -d'/' -f1-2 | sort -u
); do
  (
    cd ${x} && pkgdev manifest &&
    pkgcommit . -sS -m 'Remove old'
  )
done
pkgcheck scan --commits

Leave a Reply

Your email address will not be published.