Respect dependency graph when pushing a repository

Fixes #1218. Compute dependency graph and upload layers in the right order when pushing.