Rewrite `brew reinstall`

Fixes #23928.