Writing background
come in in your spare time. Looking at some of the content of topology discovery in the peer network, focusing on Markle tree's knowledge points, in an article (https://www.sdnlab.com/20095 ...), found a word
" A common example of a Merkle dag is the git repository ", so I looked at some of the principles of the Git repository, first of all, as follows. For your own reference and for everyone.
Git repository parsing
My question at the time:
- How does git store data that can be accurately rolled back to the established version based on the stored data?
- is git storage similar to the storage mechanism for Docker? Is it all tiered storage?
- What if git is not layered, and each commit is stored, then the amount of data is large?
doubts
Our path is to start with a new local git repository, step-by-step data and commit, and see how the content changes.
- Use
git log --pretty=oneline
to view my two commits
- Use
git cat-file -t 172b54c8cd3eedca2fc301374286c2cb807d674f
to view the type of the first commit
- Use
git cat-file -p 172b54c8cd3eedca2fc301374286c2cb807d674fe
to view content submitted for the first time
- Using
git cat-file -p 8b0c4fe1567a463214c09334b54977e0114c90fe
a tree object that looks at the first commit, you can see that a Blob object is stored in the tree object, which is the first time we commit a new file readme.md
- Use
git cat-file -p 67aeba604cea61ec63d19db0706b19d846c65ba4
to view the content of the Blob object that was submitted for the first time # # you Know
- Use
git cat-file -p 03543a4c19023da01b5114d7f7a614d95a1bf084
to view content for a second commit
- Use
git cat-file -p 03543a4c19023da01b5114d7f7a614d95a1bf084
to view the contents of a second committed tree object, including modified content and new content
- Using the
git cat-file -p 03543a4c19023da01b5114d7f7a614d95a1bf084
readme.md Blob object content to view the second commit, you can see the entire contents of the whole file, not just the modified data.
Go code
package mainimport ( "bytes" "compress/zlib" "fmt" "io" "io/ioutil" "os")//进行zlib压缩func DoZlibCompress(src []byte) []byte { var in bytes.Buffer w := zlib.NewWriter(&in) w.Write(src) w.Close() return in.Bytes()}//进行zlib解压缩func DoZlibUnCompress(compressSrc []byte) []byte { b := bytes.NewReader(compressSrc) var out bytes.Buffer r, _ := zlib.NewReader(b) io.Copy(&out, r) return out.Bytes()}func main() { args := os.Args if args == nil || len(args) < 2{ fmt.Println("Should input zlib file path.") return } b, err := ioutil.ReadFile(args[1]) if err != nil { fmt.Print(err) } fmt.Println(string(DoZlibUnCompress(b)))}
Summarize
- The article is a reference to a lot of senior blog based on the written, but also have their own practice, so it is necessary to record.
- If you have problems, try to understand and solve them, and verify them by hands-on practice.