@@ -35,6 +35,8 @@ type Batch interface {
3535// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch 
3636// To align with --batch-command, we creates the two commands both at the same time if git version is lower than 2.36 
3737type  batchCatFileWithCheck  struct  {
38+ 	ctx         context.Context 
39+ 	repoPath    string 
3840	batch       * batchCatFile 
3941	batchCheck  * batchCatFile 
4042}
@@ -49,25 +51,41 @@ func newBatchCatFileWithCheck(ctx context.Context, repoPath string) (*batchCatFi
4951	}
5052
5153	return  & batchCatFileWithCheck {
52- 		batch :      newCatFileBatch ( ctx ,  repoPath ,  "--batch" ) ,
53- 		batchCheck :  newCatFileBatch ( ctx ,  repoPath ,  "--batch-check" ) ,
54+ 		ctx :      ctx ,
55+ 		repoPath :  repoPath ,
5456	}, nil 
5557}
5658
59+ func  (b  * batchCatFileWithCheck ) getBatch () * batchCatFile  {
60+ 	if  b .batch  !=  nil  {
61+ 		return  b .batch 
62+ 	}
63+ 	b .batch  =  newCatFileBatch (b .ctx , b .repoPath , "--batch" )
64+ 	return  b .batch 
65+ }
66+ 
67+ func  (b  * batchCatFileWithCheck ) getBatchCheck () * batchCatFile  {
68+ 	if  b .batchCheck  !=  nil  {
69+ 		return  b .batchCheck 
70+ 	}
71+ 	b .batchCheck  =  newCatFileBatch (b .ctx , b .repoPath , "--batch-check" )
72+ 	return  b .batchCheck 
73+ }
74+ 
5775func  (b  * batchCatFileWithCheck ) Write (bs  []byte ) (int , error ) {
58- 	return  b .batch .Writer .Write (bs )
76+ 	return  b .getBatch () .Writer .Write (bs )
5977}
6078
6179func  (b  * batchCatFileWithCheck ) WriteCheck (bs  []byte ) (int , error ) {
62- 	return  b .batchCheck .Writer .Write (bs )
80+ 	return  b .getBatchCheck () .Writer .Write (bs )
6381}
6482
6583func  (b  * batchCatFileWithCheck ) Reader () * bufio.Reader  {
66- 	return  b .batch .Reader 
84+ 	return  b .getBatch () .Reader 
6785}
6886
6987func  (b  * batchCatFileWithCheck ) CheckReader () * bufio.Reader  {
70- 	return  b .batchCheck .Reader 
88+ 	return  b .getBatchCheck () .Reader 
7189}
7290
7391func  (b  * batchCatFileWithCheck ) Close () {
@@ -84,7 +102,9 @@ func (b *batchCatFileWithCheck) Close() {
84102// batchCommandCatFile implements the Batch interface using the "cat-file --batch-command" command 
85103// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch-command 
86104type  batchCommandCatFile  struct  {
87- 	batch  * batchCatFile 
105+ 	ctx       context.Context 
106+ 	repoPath  string 
107+ 	batch     * batchCatFile 
88108}
89109
90110var  _  Batch  =  & batchCommandCatFile {}
@@ -96,24 +116,33 @@ func newBatchCommandCatFile(ctx context.Context, repoPath string) (*batchCommand
96116	}
97117
98118	return  & batchCommandCatFile {
99- 		batch : newCatFileBatch (ctx , repoPath , "--batch-command" ),
119+ 		ctx :      ctx ,
120+ 		repoPath : repoPath ,
100121	}, nil 
101122}
102123
124+ func  (b  * batchCommandCatFile ) getBatch () * batchCatFile  {
125+ 	if  b .batch  !=  nil  {
126+ 		return  b .batch 
127+ 	}
128+ 	b .batch  =  newCatFileBatch (b .ctx , b .repoPath , "--batch-command" )
129+ 	return  b .batch 
130+ }
131+ 
103132func  (b  * batchCommandCatFile ) Write (bs  []byte ) (int , error ) {
104- 	return  b .batch .Writer .Write (append ([]byte ("contents " ), bs ... ))
133+ 	return  b .getBatch () .Writer .Write (append ([]byte ("contents " ), bs ... ))
105134}
106135
107136func  (b  * batchCommandCatFile ) WriteCheck (bs  []byte ) (int , error ) {
108- 	return  b .batch .Writer .Write (append ([]byte ("info " ), bs ... ))
137+ 	return  b .getBatch () .Writer .Write (append ([]byte ("info " ), bs ... ))
109138}
110139
111140func  (b  * batchCommandCatFile ) Reader () * bufio.Reader  {
112- 	return  b .batch .Reader 
141+ 	return  b .getBatch () .Reader 
113142}
114143
115144func  (b  * batchCommandCatFile ) CheckReader () * bufio.Reader  {
116- 	return  b .batch .Reader 
145+ 	return  b .getBatch () .Reader 
117146}
118147
119148func  (b  * batchCommandCatFile ) Close () {
0 commit comments