DIY_GIT_in_Python/how_to/Change_06.md

857 B
Raw Blame History

  • data: Add types to objects

As we will soon see, there will be different logical types of objects that are used in different contexts (even though, from the Object Databases point of view, they are just all bytes). In order to lower the chance of using an object in the wrong context were going to add a type tag for each object.

The type is just a string thats going to be prepended to the start of the file, followed by a null byte. When reading the file later well extract the type and verify that its indeed the expected type.

The default type is going to be blob, since by default an object is a collection of bytes with no further semantic meaning.

We can also pass expected=None to get_object() if we dont want to verify the type. This is useful for the cat-file CLI command which is a debug command used for printing all objects.