-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blobモデルの実装 #3
Merged
+101
−8
Merged
blobモデルの実装 #3
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eaf3fae
git logコマンドの追加
hyphen-o 83cbce0
messageの取得方法の修正
hyphen-o e4d4e2b
コマンドの修正
hyphen-o 0391bf5
log.tsの修正
hyphen-o d9985a1
commitをクラス化
hyphen-o 8f72844
コマンド入力時の待ち時間短縮
hyphen-o 15bb142
blobモデルの作成
hyphen-o 7260526
Merge branch 'main' of https://github.com/Progate/git-intern-2024-ter…
hyphen-o 805cd63
compress-buffer.tsの削除
hyphen-o a373865
addコマンドの追加
hyphen-o b6dab3c
eslintの修正
hyphen-o 5b169c4
package.json & eslintの修正
hyphen-o 02849c4
package.json & readmeの修正
hyphen-o a4f3b1d
レビュー後修正
hyphen-o a6d6f1f
ハッシュからパスを生成する処理を共通化
hyphen-o 024e5b8
contentをバイナリデータのまま圧縮するように修正
hyphen-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { readFileSync } from "node:fs"; | ||
|
||
import { coloredLog } from "../functions/colored-log.js"; | ||
import { BlobObject } from "../models/blob-object.js"; | ||
|
||
export const add = (options: Array<string>): void => { | ||
const filePath = options[0]; | ||
|
||
//引数にファイルパスが含まれていなかった場合の処理 | ||
if (!filePath) { | ||
console.log("Nothing specified, nothing added."); | ||
coloredLog({ | ||
text: "hint: Maybe you wanted to say 'git add XXX'?", | ||
color: "yellow", | ||
}); | ||
return; | ||
} | ||
|
||
const content = readFileSync(filePath); | ||
|
||
const blobObject = new BlobObject(content); | ||
blobObject.dumpBlobObject(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { join } from "node:path"; | ||
|
||
import { GIT_OBJECTS } from "../constants.js"; | ||
|
||
export const generateObjectPath = ( | ||
hash: string, | ||
): { | ||
dirPath: string; | ||
filePath: string; | ||
} => { | ||
const dirPath = join(GIT_OBJECTS, hash.slice(0, 2)); | ||
const filePath = join(GIT_OBJECTS, hash.slice(0, 2), hash.slice(2)); | ||
return { | ||
dirPath, | ||
filePath, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createHash } from "node:crypto"; | ||
import { existsSync, mkdirSync, writeFileSync } from "node:fs"; | ||
import { deflateSync } from "node:zlib"; | ||
|
||
import { generateObjectPath } from "../functions/generate-object-path.js"; | ||
|
||
export class BlobObject { | ||
constructor(private readonly content: Buffer) {} | ||
|
||
public dumpBlobObject = (): void => { | ||
const header = Buffer.from(`blob ${this.content.length.toString()}\x00`); | ||
const store = Buffer.concat([ | ||
Uint8Array.from(header), | ||
Uint8Array.from(this.content), | ||
]); | ||
|
||
//16進数表示のため,hexに変換 | ||
const hash = createHash("sha1") | ||
.update(Uint8Array.from(store)) | ||
.digest("hex"); | ||
|
||
const { dirPath, filePath } = generateObjectPath(hash); | ||
const compressedBlobObject = deflateSync(Uint8Array.from(store)); | ||
|
||
if (existsSync(filePath)) return; | ||
|
||
if (!existsSync(dirPath)) mkdirSync(dirPath); | ||
|
||
writeFileSync(filePath, Uint8Array.from(compressedBlobObject)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_から始まる変数はunused扱いされたくないので,srcとdistどちらも無視するように設定しました
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ナイスです!こういう環境整えるの大事
あとでyotsu sanにもsyncしておきましょう!
めっちゃ厳密なこと言うとPR分けた方が良いかもしれませんが、個人的にはこのくらいのサイズのPRならシュッと混ぜちゃっててもいいかなって思いました