MCPcopy Create free account
hub / github.com/cloudflare/computer / hashObjectWith

Function hashObjectWith

packages/computer/src/git/plumbing.ts:68–89  ·  view source on GitHub ↗
(opts: HashObjectWithDeps)

Source from the content-addressed store, hash-verified

66}
67
68export async function hashObjectWith(opts: HashObjectWithDeps): Promise<string> {
69 const dir = opts.dir ?? "/";
70 // hashBlob is pure (no fs) and gives us the oid without
71 // writing. When the caller asks for write, hand the bytes to
72 // writeBlob so the object lands in the store. The two paths
73 // produce identical oids for the same input, so the typed
74 // surface returns just the oid in both cases.
75 const bytes =
76 typeof opts.content === "string" ? new TextEncoder().encode(opts.content) : opts.content;
77 try {
78 if (opts.write) {
79 return await opts.git.writeBlob({ fs: opts.fs, dir, blob: bytes });
80 }
81 const { oid } = await opts.git.hashBlob({ object: bytes });
82 return oid;
83 } catch (cause) {
84 if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause });
85 throw new GitError("EHASHFAIL", `git hash-object failed: ${errorMessage(cause)}`, {
86 cause,
87 });
88 }
89}
90
91// ---------------------------------------------------------------
92// catFile

Callers 2

hashObjectFunction · 0.85
plumbing.test.tsFile · 0.85

Calls 4

isNotARepositoryCauseFunction · 0.85
writeBlobMethod · 0.80
hashBlobMethod · 0.80
errorMessageFunction · 0.70

Tested by

no test coverage detected