Git tree objects.

c-declarations
Joshua Potter 2024-03-02 05:12:57 -07:00
parent 3cc9d74d05
commit d27412d5c7
3 changed files with 285 additions and 28 deletions

View File

@ -181,7 +181,7 @@
"_journal/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048", "_journal/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
"_journal/2024-02/2024-02-16.md": "e701902e369ec53098fc2deed4ec14fd", "_journal/2024-02/2024-02-16.md": "e701902e369ec53098fc2deed4ec14fd",
"binary/integer-encoding.md": "7ace6ab6c5a4191ae0abdfe7e5abb6a2", "binary/integer-encoding.md": "7ace6ab6c5a4191ae0abdfe7e5abb6a2",
"combinatorics/index.md": "200f23380b0817cc13a9acd40996b125", "combinatorics/index.md": "477bfcad2d88edfb823072b8afb9d236",
"_journal/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629", "_journal/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
"_journal/2024-02/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048", "_journal/2024-02/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
"combinatorics/multiplicative-principle.md": "f1430302e0a35b863fa965a834c4e40a", "combinatorics/multiplicative-principle.md": "f1430302e0a35b863fa965a834c4e40a",
@ -217,14 +217,15 @@
"_journal/2024-02/2024-02-27.md": "f75a0d04a875aeee932343dae0c78768", "_journal/2024-02/2024-02-27.md": "f75a0d04a875aeee932343dae0c78768",
"filesystems/index.md": "cbd2b0290a3ba3b32abec4bd8bfefad5", "filesystems/index.md": "cbd2b0290a3ba3b32abec4bd8bfefad5",
"filesystems/cas.md": "34906013a2a60fe5ee0e31809b4838aa", "filesystems/cas.md": "34906013a2a60fe5ee0e31809b4838aa",
"git/objects.md": "b49015b8ebffc2c976d97b2484c74448", "git/objects.md": "b95228a78744d3f9fe173e575aa0445a",
"git/index.md": "83d2d95fc549d9e8436946c7bd058d15", "git/index.md": "83d2d95fc549d9e8436946c7bd058d15",
"encoding/integer.md": "5dd3a961bf259e53da207209051b8335", "encoding/integer.md": "5dd3a961bf259e53da207209051b8335",
"_journal/2024-02-29.md": "f610f3caed659c1de3eed5f226cab508", "_journal/2024-02-29.md": "f610f3caed659c1de3eed5f226cab508",
"_journal/2024-02/2024-02-28.md": "7489377c014a2ff3c535d581961b5b82", "_journal/2024-02/2024-02-28.md": "7489377c014a2ff3c535d581961b5b82",
"_journal/2024-03-01.md": "e5602f6d41ae9dde85385428ad637d5a", "_journal/2024-03-01.md": "a532486279190b0c12954966cbf8c3fe",
"_journal/2024-02/2024-02-29.md": "0e502a2c8baf90c2f12859b03f10b5a1", "_journal/2024-02/2024-02-29.md": "0e502a2c8baf90c2f12859b03f10b5a1",
"algebra/sequences.md": "97c217823aacf8910a1a37bde694ecfe" "algebra/sequences.md": "97c217823aacf8910a1a37bde694ecfe",
"algebra/sequences/index.md": "e5a7cdfbcb61709ce2963c4b5e53a8f2"
}, },
"fields_dict": { "fields_dict": {
"Basic": [ "Basic": [

View File

@ -13,3 +13,4 @@ title: "2024-03-01"
* Reviewed database reading/videos from yesterday with Kevin. * Reviewed database reading/videos from yesterday with Kevin.
* Finished planning soft skills course with Gus. * Finished planning soft skills course with Gus.
* Added flashcards around sequences. * Added flashcards around sequences.
* Added flashcards for git trees.

View File

@ -10,6 +10,8 @@ tags:
## Overview ## Overview
Git has a few fundamental types that serve as the foundation for its [[cas|CAS]] system, expanded upon in each subsequent section.
%%ANKI %%ANKI
Basic Basic
What cryptographic hash function does git use internally? What cryptographic hash function does git use internally?
@ -106,22 +108,6 @@ Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Soft
<!--ID: 1709177255627--> <!--ID: 1709177255627-->
END%% END%%
%%ANKI
Basic
What plumbing subcommand is used to generate an oid?
Back: `hash-object`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255632-->
END%%
%%ANKI
Basic
The `hash-object` subcommand optionally stores the resulting object in what directory?
Back: `.git/objects`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255637-->
END%%
%%ANKI %%ANKI
Cloze Cloze
The {object database} refers to the {`.git/objects`} directory. The {object database} refers to the {`.git/objects`} directory.
@ -129,10 +115,132 @@ Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Soft
<!--ID: 1709177255644--> <!--ID: 1709177255644-->
END%% END%%
%%ANKI
Basic
Where does e.g. `d670460b4b4aece5915caf5c68d12f560a9fe3e4` live in the object database?
Back: At `.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4`.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255668-->
END%%
%%ANKI
Basic
What regular files exist in the object database after `git init`?
Back: None.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255672-->
END%%
%%ANKI
Basic
Files in the object database are compressed using what format?
Back: The `zlib` data format.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254695-->
END%%
%%ANKI
Basic
What compression library does git use internally?
Back: `zlib`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254701-->
END%%
%%ANKI
Basic
How do you decode e.g. `.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4`?
Back: By decompressing the `zlib` data formatted file.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254705-->
END%%
%%ANKI
Basic
What plumbing subcommand is used to inspect git objects?
Back: `cat-file`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254709-->
END%%
%%ANKI
Basic
What plumbing subcommand is typically used over manually decompressing with `zlib`?
Back: `cat-file`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254713-->
END%%
%%ANKI
Basic
What is the difference in output of manually decompressing `<OID>` and the following?
```bash
$ git cat-file -p <OID>
```
Back: Manual decompression includes the object header.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254716-->
END%%
## Blobs
The **b**inary **l**arge **ob**ject (blob) is used to represent arbitrary files.
%%ANKI
Basic
Why are git blobs named the way they are?
Back: It is an acronym for **b**inary **l**arge **ob**ject.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254720-->
END%%
%%ANKI
Basic
A regular file is stored as what kind of git object?
Back: A blob.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254723-->
END%%
%%ANKI
Basic
What does the decompressed header of a blob object look like?
Back: `blob <size><NUL>`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254726-->
END%%
%%ANKI
Basic
What is the value of `<size>` found in the header of a blob file?
Back: The number of bytes of the decompressed content.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254730-->
END%%
%%ANKI
Basic
What is the decompressed text of the blob generated by the following?
```bash
$ echo -n "abcd" | git hash-object -w --stdin
```
Back: `blob 4\0abcd`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254733-->
END%%
%%ANKI
Basic
The `hash-object` subcommand optionally stores a created object in what directory?
Back: `.git/objects`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255637-->
END%%
%%ANKI %%ANKI
Basic Basic
What does the `hash-object` subcommand return? What does the `hash-object` subcommand return?
Back: The computed object id. Back: The oid of the new blob object.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014). Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255651--> <!--ID: 1709177255651-->
END%% END%%
@ -155,18 +263,165 @@ END%%
%%ANKI %%ANKI
Basic Basic
Where does object e.g. `d670460b4b4aece5915caf5c68d12f560a9fe3e4` live in the object database? What is the result of the following command?
Back: At `.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4`. ```bash
$ echo -n "abcd" | git hash-object --stdin
```
Back: An oid (usually a SHA-1 hash).
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014). Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255668--> <!--ID: 1709345254736-->
END%% END%%
%%ANKI %%ANKI
Basic Basic
What regular files exist in the object database after `git init`? What plumbing subcommand is used to create blobs?
Back: None. Back: `hash-object`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014). Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709177255672--> <!--ID: 1709348481684-->
END%%
## Trees
The tree is used to represent directories. It maintains filenames of any contained blobs.
%%ANKI
Basic
What git object maintains filenames?
Back: Trees.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481689-->
END%%
%%ANKI
Basic
A directory is stored as what kind of git object?
Back: Trees.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481693-->
END%%
%%ANKI
Basic
All the *content* of a git repository is stored as what kind of git objects?
Back: Trees and blobs.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481696-->
END%%
%%ANKI
Cloze
A regular file is to {blob} objects as directories are to {tree} objects.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709345254740-->
END%%
%%ANKI
Cloze
{`hash-object`} is to blobs as {`write-tree`} is to trees.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481699-->
END%%
%%ANKI
Basic
What does the decompressed header of a tree object look like?
Back: `tree <size><NUL>`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481704-->
END%%
%%ANKI
Basic
What does the decompressed header of an empty tree object look like?
Back: `tree 0<NUL>`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481711-->
END%%
%%ANKI
Basic
What plumbing subcommand is used to create trees?
Back: `write-tree`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481715-->
END%%
%%ANKI
Basic
The `write-tree` subcommand stores the new tree object in what directory?
Back: `.git/objects`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481718-->
END%%
%%ANKI
Basic
The `write-tree` subcommand creates a tree object from what?
Back: The current index.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481721-->
END%%
%%ANKI
Basic
What does the `write-tree` subcommand return?
Back: The oid of the new tree object.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481725-->
END%%
%%ANKI
Basic
Why doesn't `write-tree` take any arguments?
Back: It creates a new tree from the current index.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709348481730-->
END%%
%%ANKI
Basic
What plumbing subcommand is used to put tree objects into the staging area?
Back: `read-tree`
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709349279634-->
END%%
%%ANKI
Basic
How does the following command update the index?
```bash
$ git read-tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579
```
Back: It adds the contents of tree `d8329fc1cc938780ffdd9f94e0d364e0ea74f579`.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709349279641-->
END%%
%%ANKI
Basic
How does the following command update the index?
```bash
$ git read-tree --prefix=foo d8329fc1cc938780ffdd9f94e0d364e0ea74f579
```
Back: It adds tree `d8329fc1cc938780ffdd9f94e0d364e0ea74f579` as subtree `foo`.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709349279646-->
END%%
%%ANKI
Basic
Where does the `read-tree` subcommand read the tree into?
Back: The current index.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709349279652-->
END%%
%%ANKI
Basic
The `read-tree` and `write-tree` interact indirectly through what?
Back: The staging area.
Reference: Scott Chacon, *Pro Git*, Second edition, The Experts Voice in Software Development (New York, NY: Apress, 2014).
<!--ID: 1709349279660-->
END%% END%%
## References ## References