File tree Expand file tree Collapse file tree 4 files changed +27
-10
lines changed Expand file tree Collapse file tree 4 files changed +27
-10
lines changed Original file line number Diff line number Diff line change 1+ ## next
2+
3+ - Fixed methods for reading loose objects (` readObjectHeaderByOid ` , ` readObjectHeaderByHash ` , ` readObjectByOid `
4+ and ` readObjectByHash ` ) that were not working in some cases due to incorrect formation of the fanout table when ` fs.readdir() ` returns an unsorted list of entries
5+ - Fixed ` listRemotes() ` method to always return a sorted list of remotes
6+
17## 0.1.0 (2022-09-12)
28
39- Initial release
Original file line number Diff line number Diff line change @@ -30,13 +30,12 @@ async function createLooseObjectMap(gitdir: string): Promise<LooseObjectMap> {
3030 )
3131 ) ;
3232
33- return new Map ( objectDirs . flat ( ) ) ;
33+ return new Map ( objectDirs . flat ( ) . sort ( ( [ a ] , [ b ] ) => ( a < b ? - 1 : 1 ) ) ) ;
3434}
3535
36- function indexObjectNames ( names : string [ ] ) {
36+ function indexObjectNames ( sortedNames : string [ ] ) {
3737 const fanoutTable = new Array < [ start : number , end : number ] > ( 256 ) ;
38- const sortedNames = [ ...names ] . sort ( ( [ a ] , [ b ] ) => ( a < b ? - 1 : 1 ) ) ;
39- const binaryNames = Buffer . from ( names . join ( '' ) , 'hex' ) ;
38+ const binaryNames = Buffer . from ( sortedNames . join ( '' ) , 'hex' ) ;
4039
4140 for ( let i = 0 , offset = 0 ; i < 256 ; i ++ ) {
4241 const prevOffset = offset ;
Original file line number Diff line number Diff line change @@ -256,7 +256,7 @@ async function readRemotes(gitdir: string) {
256256 }
257257 }
258258
259- return remotes ;
259+ return remotes . sort ( ) ;
260260}
261261
262262async function readLooseRefs ( gitdir : string , remotes : string [ ] ) {
Original file line number Diff line number Diff line change @@ -9,11 +9,23 @@ export const fixtures = Object.create(null);
99
1010for ( const name of fixtureNames ) {
1111 fixtures [ name ] = {
12- repo : ( options ?: GitReaderOptions ) =>
13- createGitReader (
14- fileURLToPath ( new URL ( fixturesPath + name + '/_git' , import . meta. url ) ) ,
15- options
16- ) ,
12+ repo : ( options ?: GitReaderOptions ) => {
13+ const origReaddir = fs . promises . readdir ;
14+
15+ try {
16+ // Patch readdir method to catch issues when readdir returns unsorted entries
17+ // @ts -expect-error ts(2322)
18+ fs . promises . readdir = ( ...args : Parameters < typeof fs . promises . readdir > ) =>
19+ origReaddir ( ...args ) . then ( ( list ) => list . reverse ( ) ) ;
20+
21+ return createGitReader (
22+ fileURLToPath ( new URL ( fixturesPath + name + '/_git' , import . meta. url ) ) ,
23+ options
24+ ) ;
25+ } finally {
26+ fs . promises . readdir = origReaddir ;
27+ }
28+ } ,
1729 data : JSON . parse (
1830 fs . readFileSync (
1931 fileURLToPath ( new URL ( fixturesPath + name + '/data.json' , import . meta. url ) ) ,
You can’t perform that action at this time.
0 commit comments