Exact format of tree objets

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Exact format of tree objets

From: Chico Sokol <hidden>
Date: 2016-06-15 22:57:41

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?

We're suspecting that there is some kind of special format or
encoding, because the command "git cat-file -p <sha>" show me the
expected output, something like:

100644 blob 2beae51a0e14b3167fd7e81119972caef95779f4    .gitignore
100644 blob 7c817960e954f0278a6eee8d58611f61445167e8    LICENSE.txt
100644 blob 30e849cba985d74bfd29696f6dee5a40abaacb03    README
...


While "git cat-file tree <sha>" generate an strange output, which
indicate some kink of encoding problem. Something like:

100644 .gitignore+��▒����,��Wy�100644
LICENSE.txt|�y`�T�'�n��XaaDQg�100644 README0�I˩��K�)


Thanks,







--
Chico Sokol

Re: Exact format of tree objets

From: Ilari Liusvaara <hidden>
Date: 2016-06-15 22:57:41

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

Re: Exact format of tree objets

From: Chico Sokol <hidden>
Date: 2016-06-15 22:57:48

What is the encoding of the filename?


--
Chico Sokol


On Tue, Jun 11, 2013 at 3:26 PM, Ilari Liusvaara
[off-list ref] wrote:
On Tue, Jun 11, 2013 at 01:25:14PM -0300, Chico Sokol wrote:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help