Building Git in Elixir — Part 2 (Store Trees & Initial Commit)
In the previous article of this series, I focused on initializing repository and storing blobs for file content. In this article, I will focus on storing trees and first commit.
A Bit of Theory
As explained in previous article, a tree stores certain information about the stored blobs. It is one more level of indirection above blobs for easier lookup. If we examine Git’s objects database using git cat-file
command we can see —
Here, commit 88e38705fdbd3608cddbe904b67c731f3234c45b is a tree and as we can see it stores a list of entries. Each entry contains the file’s mode (100644), the word blob, the object ID for entry and file’s name.
Likewise, a git commit is stored as below —
Here, commit 6554ab08c8844fe9c85346a7f2bf021614e2db93 stores information about pointer to a tree, author and committer information, timestamp, and the commit message.
To populate the author name and email, there are multiple ways but typically a ~/.gitconfig is used which looks like —
But in this article, we will pass these information via environment variables which I will explain later.