MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / readObject

Function readObject

src/api/readObject.js:203–276  ·  view source on GitHub ↗
({
  fs: _fs,
  dir,
  gitdir = join(dir, '.git'),
  oid,
  format = 'parsed',
  filepath = undefined,
  encoding = undefined,
  cache = {},
})

Source from the content-addressed store, hash-verified

201 *
202 */
203export async function readObject({
204 fs: _fs,
205 dir,
206 gitdir = join(dir, '.git'),
207 oid,
208 format = 'parsed',
209 filepath = undefined,
210 encoding = undefined,
211 cache = {},
212}) {
213 try {
214 assertParameter('fs', _fs)
215 assertParameter('gitdir', gitdir)
216 assertParameter('oid', oid)
217
218 const fs = new FileSystem(_fs)
219 const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir })
220 if (filepath !== undefined) {
221 oid = await resolveFilepath({
222 fs,
223 cache,
224 gitdir: updatedGitdir,
225 oid,
226 filepath,
227 })
228 }
229 // GitObjectManager does not know how to parse content, so we tweak that parameter before passing it.
230 const _format = format === 'parsed' ? 'content' : format
231 const result = await _readObject({
232 fs,
233 cache,
234 gitdir: updatedGitdir,
235 oid,
236 format: _format,
237 })
238 result.oid = oid
239 if (format === 'parsed') {
240 result.format = 'parsed'
241 switch (result.type) {
242 case 'commit':
243 result.object = GitCommit.from(result.object).parse()
244 break
245 case 'tree':
246 result.object = GitTree.from(result.object).entries()
247 break
248 case 'blob':
249 // Here we consider returning a raw Buffer as the 'content' format
250 // and returning a string as the 'parsed' format
251 if (encoding) {
252 result.object = result.object.toString(encoding)
253 } else {
254 result.object = new Uint8Array(result.object)
255 result.format = 'content'
256 }
257 break
258 case 'tag':
259 result.object = GitAnnotatedTag.from(result.object).parse()
260 break

Callers 15

resolveBlobFunction · 0.85
_resolveFileIdFunction · 0.85
_resolveFilepathFunction · 0.85
resolveCommitFunction · 0.85
_checkoutFunction · 0.85
updateWorkingDirFunction · 0.85
_readTagFunction · 0.85
_fetchFunction · 0.85
getExternalRefDeltaFunction · 0.85
walkFunction · 0.85
getExternalRefDeltaFunction · 0.85
_annotatedTagFunction · 0.85

Calls 9

joinFunction · 0.90
assertParameterFunction · 0.90
discoverGitdirFunction · 0.90
resolveFilepathFunction · 0.90
_readObjectFunction · 0.90
parseMethod · 0.45
fromMethod · 0.45
entriesMethod · 0.45
toStringMethod · 0.45

Tested by 2

getExternalRefDeltaFunction · 0.68
getExternalRefDeltaFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…