diff --git a/CHANGELOG.md b/CHANGELOG.md index bc58409..54bac45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## next +- Fixed size computation of on-disk reverse index (`.rev` files) + +## 0.1.2 (2023-10-12) + - Added `getPathEntry()` method - Added `getPathsEntries()` method - Fixed reading on-disk reverse index (`.rev` files) diff --git a/fixtures/rev-index/data.json b/fixtures/rev-index/data.json index a0ac51a..1e67618 100644 --- a/fixtures/rev-index/data.json +++ b/fixtures/rev-index/data.json @@ -7379,7 +7379,7 @@ }, "reverseIndex": { "path": "objects/pack/pack-43bc2b9ae5b7a56ab22e849c6c1dfaa00ba72ab1.rev", - "size": 4880 + "size": 1264 } } ] diff --git a/src/packed-rev.ts b/src/packed-rev.ts index d6fe3c4..b142c4f 100644 --- a/src/packed-rev.ts +++ b/src/packed-rev.ts @@ -20,7 +20,10 @@ export class PackReverseIndex { private index: PackIndex, private reverseIndex: Uint32Array ) { - this.filesize = this.filename !== null ? reverseIndex.byteLength + 12 + 20 : 0; + this.filesize = + this.filename !== null + ? reverseIndex.byteLength + 12 + 20 + 20 // + header + checksum of the corresponding packfile + checksum of the index file + : 0; } indexByOffsetToIndexByName(index: number) { @@ -52,7 +55,7 @@ export async function readPackRevFile( if (existsSync(fullRevFilename)) { try { - const packSize = packFilesize - 20; // 20bytes for trailer + const packSize = packFilesize - 20; // 20bytes for trailer (checksum) // https://git-scm.com/docs/pack-format#_pack_rev_files_have_the_format fh = await fsPromises.open(fullRevFilename); @@ -72,7 +75,7 @@ export async function readPackRevFile( const reverseIndex = new Uint32Array( buffer.buffer, buffer.byteOffset + 12, - buffer.byteLength - 12 + packIndex.size ); // swap numbers to avoid using readUInt32BE() and less math with indexes