Another way to tackle this, possibly easier, would be to allow multiple old versions to remain in the archive, as in bug 316818. Then you don't need to think about calculating the dependencies.
Another way to tackle this, possibly easier, would be to allow multiple old versions to remain in the archive, as in bug 316818. Then you don't need to think about calculating the dependencies.