tsorting the packages being replaced according to their interdependencies, which avoids most duplicate rebuilds.