Implement deps log recompaction.

Fixes issue #554.

The third commit is a bit tricky, but I think it doesn't change existing behavior.

The `swap()` call in the fourth commit also feels a bit strange, but I think it's the right thing given the data model.