[WIP] Fill the tree cache when reading in a tree into an index

It is convenient to use a standalone index as a way to perform some modifications to a tree at arbitrary levels. When doing this however, we did not fill the cache, which means we'd end up calculating a lot of trees which are already in the repository.

Filling the index on read means we can skip a lot of work; I also think that the current behaviour could lead to having the wrong cache entries.

I've marked this as WIP as this still needs a ton of tests to check that the cache is correct. We also still don't write out the cache when writing out the index to disk for the same lack of being completely sure about it being correct, much the same as git does.