Refactor to simplify clone logic, and avoid circular imports.
Move some ref-only operations to dulwich.refs.