Skip to content

Commit

Permalink
Fix size computation of on-disk reverse index
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Oct 13, 2023
1 parent c06578f commit 861464e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fixtures/rev-index/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7379,7 +7379,7 @@
},
"reverseIndex": {
"path": "objects/pack/pack-43bc2b9ae5b7a56ab22e849c6c1dfaa00ba72ab1.rev",
"size": 4880
"size": 1264
}
}
]
Expand Down
9 changes: 6 additions & 3 deletions src/packed-rev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 861464e

Please sign in to comment.