@@ -6,19 +6,20 @@ import { createPackedObjectIndex } from './packed-object-index.js';
6
6
import { createFilesMethods } from './files-methods.js' ;
7
7
import { createCommitMethods } from './commits.js' ;
8
8
import { createStatMethod } from './stat.js' ;
9
+ import { promiseAllThreaded } from './utils/threads.js' ;
9
10
import { GitReaderOptions , NormalizedGitReaderOptions , CruftPackMode } from './types' ;
10
11
11
12
export * from './types.js' ;
12
13
export * from './parse-object.js' ;
13
14
export { isGitDir , resolveGitDir } ;
14
15
15
- export async function createGitReader ( gitdir : string , options ?: GitReaderOptions ) {
16
+ export async function createGitReader ( gitdir : string , options ?: Partial < GitReaderOptions > ) {
16
17
const startInitTime = Date . now ( ) ;
17
18
const normalizedOptions = normalizeOptions ( options ) ;
18
19
const resolvedGitDir = await resolveGitDir ( gitdir ) ;
19
20
const [ refIndex , looseObjectIndex , packedObjectIndex ] = await Promise . all ( [
20
- createRefIndex ( resolvedGitDir ) ,
21
- createLooseObjectIndex ( resolvedGitDir ) ,
21
+ createRefIndex ( resolvedGitDir , normalizedOptions ) ,
22
+ createLooseObjectIndex ( resolvedGitDir , normalizedOptions ) ,
22
23
createPackedObjectIndex ( resolvedGitDir , normalizedOptions )
23
24
] ) ;
24
25
const { readObjectHeaderByHash, readObjectByHash, readObjectHeaderByOid, readObjectByOid } =
@@ -38,27 +39,30 @@ export async function createGitReader(gitdir: string, options?: GitReaderOptions
38
39
async dispose ( ) {
39
40
await Promise . all ( [ looseObjectIndex . dispose ( ) , packedObjectIndex . dispose ( ) ] ) ;
40
41
} ,
41
- stat : createStatMethod ( {
42
- gitdir : resolvedGitDir ,
43
- refIndex,
44
- looseObjectIndex,
45
- packedObjectIndex
46
- } ) ,
42
+ stat : createStatMethod (
43
+ resolvedGitDir ,
44
+ { refIndex, looseObjectIndex, packedObjectIndex } ,
45
+ normalizedOptions
46
+ ) ,
47
47
48
48
initTime : Date . now ( ) - startInitTime
49
49
} ;
50
50
}
51
51
52
- function normalizeOptions ( options ?: GitReaderOptions ) : NormalizedGitReaderOptions {
53
- if ( ! options || options . cruftPacks === undefined ) {
54
- return { cruftPacks : 'include' } ;
55
- }
52
+ function normalizeOptions ( options ?: Partial < GitReaderOptions > ) : NormalizedGitReaderOptions {
53
+ const { cruftPacks = true , maxConcurrency } = options || { } ;
54
+ const maxConcurrencyNormalized = Number . isFinite ( maxConcurrency )
55
+ ? ( maxConcurrency as number )
56
+ : 50 ;
56
57
57
58
return {
59
+ maxConcurrency : maxConcurrencyNormalized ,
60
+ performConcurrent : ( queue , action ) =>
61
+ promiseAllThreaded ( maxConcurrencyNormalized , queue , action ) ,
58
62
cruftPacks :
59
- typeof options . cruftPacks === 'string'
60
- ? validateCruftPackMode ( options . cruftPacks )
61
- : options . cruftPacks // expands true/false aliases
63
+ typeof cruftPacks === 'string'
64
+ ? validateCruftPackMode ( cruftPacks )
65
+ : cruftPacks // expands true/false aliases
62
66
? 'include'
63
67
: 'exclude'
64
68
} ;
0 commit comments