| 63 | } |
| 64 | |
| 65 | async readdir(entry) { |
| 66 | const filepath = entry._fullpath |
| 67 | const { fs, cache, gitdir } = this |
| 68 | const map = await this.mapPromise |
| 69 | const obj = map.get(filepath) |
| 70 | if (!obj) throw new Error(`No obj for ${filepath}`) |
| 71 | const oid = obj.oid |
| 72 | if (!oid) throw new Error(`No oid for obj ${JSON.stringify(obj)}`) |
| 73 | if (obj.type !== 'tree') { |
| 74 | // TODO: support submodules (type === 'commit') |
| 75 | return null |
| 76 | } |
| 77 | const { type, object } = await readObject({ fs, cache, gitdir, oid }) |
| 78 | if (type !== obj.type) { |
| 79 | throw new ObjectTypeError(oid, type, obj.type) |
| 80 | } |
| 81 | const tree = GitTree.from(object) |
| 82 | // cache all entries |
| 83 | for (const entry of tree) { |
| 84 | map.set(join(filepath, entry.path), entry) |
| 85 | } |
| 86 | return tree.entries().map(entry => join(filepath, entry.path)) |
| 87 | } |
| 88 | |
| 89 | async type(entry) { |
| 90 | if (entry._type === false) { |