Re: Exact format of tree objets
- From
- Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
- Date
- Jun 11, 2013, 18:26 UTC
- Message-ID
- <20130611182649.GA24704@LK-Perkele-VII>
- In-Reply-To
- <CABx5MBRAYmO39BnMqnHZhUOwQf-7yeRuD=m7-P2xXdhkp6aWpA@mail.gmail.com>
On Tue, Jun 11, 2013 at 01:25:14PM -0300, Chico Sokol wrote:
> Is there any official documentation of tree objets format? Are tree > objects encoded specially in some way? How can I parse the inflated > contents of a tree object?
Tree object consists of entries, each concatenation of: - Octal mode (using ASCII digits 0-7). - Single SPACE (0x20) - Filename - Single NUL (0x00) - 20-byte binary SHA-1 of referenced object.
At least following octal modes are known: 40000: Directory (tree). 100644: Regular file (blob). 100755: Executable file (blob). 120000: Symbolic link (blob). 160000: Submodule (commit).
The entries are always sorted in (bytewise) lexicographical order, except directories sort like there was impiled '/' at the end.
So e.g.: ! < 0 < 9 < a < a- < a- (directory) < a (directory) < a0 < ab < b < z.
The idea of sorting directories specially is that if one recurses upon hitting a directory and uses '/' as path separator, then the full filenames are in bytewise lexicographical order.
-Ilari