@@ -23,24 +23,24 @@ import (
2323func SearchPointerBlobs (ctx context.Context , repo * git.Repository , pointerChan chan <- PointerBlob , errChan chan <- error ) {
2424 basePath := repo .Path
2525
26- fail := func (err error ) {
27- errChan <- err
28- close (pointerChan )
29- close (errChan )
26+ // We will need to run batch-check on all the objects in the repository
27+ // in Git 2.6.0+ we can use `git cat-file --batch-check --batch-all-objects`
28+ // However in earlier versions we'll need to use rev-list to get the objects.
29+ gitHasBatchCheckAllObjects := git .CheckGitVersionAtLeast ("2.6.0" ) == nil
30+
31+ numPipesRequired := 3
32+ if ! gitHasBatchCheckAllObjects {
33+ numPipesRequired += 2
3034 }
3135
32- pipes , err := git .NewPipePairs (3 )
36+ pipes , err := git .NewPipePairs (numPipesRequired )
3337 if err != nil {
34- fail (err )
38+ errChan <- err
39+ close (pointerChan )
40+ close (errChan )
3541 return
3642 }
37-
38- closeAll := func (err error ) {
39- for _ , closer := range pipes {
40- _ = closer .CloseWithError (err )
41- }
42- }
43- defer closeAll (nil )
43+ defer pipes .Close ()
4444
4545 catFileCheckReader , catFileCheckWriter := pipes [0 ].ReaderWriter ()
4646 shasToBatchReader , shasToBatchWriter := pipes [1 ].ReaderWriter ()
@@ -62,20 +62,9 @@ func SearchPointerBlobs(ctx context.Context, repo *git.Repository, pointerChan c
6262 go pipeline .BlobsLessThan1024FromCatFileBatchCheck (catFileCheckReader , shasToBatchWriter , & wg )
6363
6464 // 1. Run batch-check on all objects in the repository
65- if git .CheckGitVersionAtLeast ("2.6.0" ) != nil {
66-
67- morePipes , err := git .NewPipePairs (2 )
68- if err != nil {
69- wg .Done ()
70- closeAll (err )
71- wg .Wait ()
72- fail (err )
73- return
74- }
75-
76- revListReader , revListWriter := morePipes [0 ].ReaderWriter ()
77- shasToCheckReader , shasToCheckWriter := morePipes [1 ].ReaderWriter ()
78- pipes = append (pipes , morePipes ... )
65+ if ! gitHasBatchCheckAllObjects {
66+ revListReader , revListWriter := pipes [3 ].ReaderWriter ()
67+ shasToCheckReader , shasToCheckWriter := pipes [4 ].ReaderWriter ()
7968
8069 wg .Add (2 )
8170 go pipeline .CatFileBatchCheck (ctx , shasToCheckReader , catFileCheckWriter , & wg , basePath )
0 commit comments