Support the 'TREE' extension in .git/index through DirCache
We now support reading and writing the 'TREE' extension of the 'DIRC'
file format. C Git uses this as an optional extension to cache the
SHA-1 id of each tree object used by the index, permitting C Git to
identify subsections of the repository which have not been modified
and to speed up the git-write-tree plumbing command prior to making
a commit object.
Our support includes constructing the tree objects if they do not
exist, but we don't write them to the object database. This change
only builds the ranges within the index file and marks them invalid,
so C Git knows that the tree must be generated and saved into the
object database before it can rely upon it in a commit.
Like the DirCacheEntry objects we try to avoid unnecessary encode
and decode operations during reads and writes as they would just
drag down the processor.
Our sort ordering of the 'TREE' data is different from that of C Git.
C Git sorts tree children according to lengths of path names, as the
actual order was not relevant but Junio wanted a stable ordering. We
want our tree children sorted by name so we can merge-sort them onto
the main index entries. That means we may have to sort the children
after we read them from disk; at least that is true if C Git was the
last process to write the index file.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>