pull: some optimisations
The main optimisation is a much more aggressive use of transactions, which yields a ~33% speedup when importing Dulwich. We use one transaction for each map-save-interval. Previously, the default would be everything, but that's a bit hazardous, as it makes it very easy to lose a very long-running import. Instead, now that we use transactions, I adjusted the behaviour to never save the map during a clone, and save it every 1000th commit on pull.
I manually tested this with by interrupting a pull or clone, and in some cases, the rollback would fail, leaving a corrupt repository. Could this be caused by nested or duplicate transactions? EDIT: I grafted 4382a78fd9b1 into this, and it seemed to fix the corruption.
Other minor optimisations remove some unnecessary I/O.