gitのつくりかた yapc::asia 2015 @dqneo

Post on 18-Feb-2017

13.419 Views

Category:

Engineering

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Gitのつくりかた How to make a Git

YAPC::Asia 2015 @DQNEO

@DQNEO (どきゅねお)

就職しますた Got a job !!

“Gitを理解する最良の方法、 それは自分でGitを

実装してみることです”

“Gitを理解する最良の方法、 それは自分でGitを

実装してみることです” ̶ DQNEO ̶

Gitとは何か? What is Git ?

バージョン管理システム Version Controle System

バージョン管理システム Version Controle System

見方を変えてみよう Take a look in another way

中から見た場合 View inside

コンテンツ管理システム Contents Management System

コンテンツとは何か? What is Content ?

ソースコードだったり Source Code

画像だったり Image

Gitはコンテンツをどのように 格納しているのか?

How does Git store contents?

キーバリューストア Key Value Store

Key

3b18e512dba79e4c8300dd08aeb37f8e728b8dad

sha1 hash

.git/objects/3b/18e2. . . .

Key

$ hexdump -C .git/objects/3b/18e512…

78 01 4b ca c9 4f 52 30 34 62 c8 48 cd c9 c9 57 28 cf 2f ca 49 e1 02 00 44 11 06 89

Value

zlib圧縮されたナニカ

Valueの作り方

“hello world\n”

Valueの作り方

“hello world\n”=> 12 bytes

Valueの作り方

“blob 12\0hello world\n”

Valueの作り方

“blob 12\0hello world\n”↑これをzlib圧縮する

$ hexdump -C .git/objects/3b/18e512…

78 01 4b ca c9 4f 52 30 34 62 c8 48 cd c9 c9 57 28 cf 2f ca 49 e1 02 00 44 11 06 89

Value

圧縮して保存 : git add 解凍して取得 : git cat-file -p

作ってみよう!11 Let’s make it !!

git cat-file -p => KVSからgetするコマンド

zlib解凍

$ my_git_cat_file-p 18/e512dba79e4c830 hello world

my_git_cat_file-pコマンド

これを応用すれば git checkout ができる

こんな感じで1個ずつサブコマンドを作っていけば

Gitはつくれる!! You can make a Git !!

https://github.com/DQNEO/minigit

作ってみた(途中まで)

ご清聴ありがとうございました。 Thank you !

人材募集中! We are hiring !

top related