Add writeTree support to DirCache
This way we can write a full tree from the DirCache, including reusing
any valid tree entries stored within the 'TREE' cache extension. By
reusing those entries we can avoid generating the tree objects that
are already stored in the Git repository.
The algorithm may cause up to 3 passes over the DirCache entries:
* Pass 1: Compute the tree structure
* Pass 2: Compute the sizes of each tree
* Pass 3: Write the tree object to the object store
These extra passes cause more CPU time to be expended in exchange
for a lower memory requirement during the tree writing. The code
is only formatting the lowest level leaf tree which has not yet
been written to the object store, so higher level trees do not
occupy memory while they are waiting for the leaves to write out.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>