@@ -23,40 +23,6 @@ func (b *batchCatFile) Close() {
2323 }
2424}
2525
26- // NewBatch creates a new batch for the given repository, the Close must be invoked before release the batch
27- func newBatch (ctx context.Context , repoPath string ) (* batchCatFile , error ) {
28- // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
29- if err := ensureValidGitRepository (ctx , repoPath ); err != nil {
30- return nil , err
31- }
32-
33- var batch batchCatFile
34- batch .Writer , batch .Reader , batch .cancel = catFileBatch (ctx , repoPath , "--batch" )
35- return & batch , nil
36- }
37-
38- func newBatchCheck (ctx context.Context , repoPath string ) (* batchCatFile , error ) {
39- // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
40- if err := ensureValidGitRepository (ctx , repoPath ); err != nil {
41- return nil , err
42- }
43-
44- var check batchCatFile
45- check .Writer , check .Reader , check .cancel = catFileBatchCheck (ctx , repoPath )
46- return & check , nil
47- }
48-
49- func newBatchCommand (ctx context.Context , repoPath string ) (* batchCatFile , error ) {
50- // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
51- if err := ensureValidGitRepository (ctx , repoPath ); err != nil {
52- return nil , err
53- }
54-
55- var check batchCatFile
56- check .Writer , check .Reader , check .cancel = catFileBatch (ctx , repoPath , "--batch-command" )
57- return & check , nil
58- }
59-
6026type Batch interface {
6127 Write ([]byte ) (int , error )
6228 WriteCheck ([]byte ) (int , error )
@@ -75,20 +41,22 @@ type batchCatFileWithCheck struct {
7541
7642var _ Batch = & batchCatFileWithCheck {}
7743
44+ // newBatchCatFileWithCheck creates a new batch and a new batch check for the given repository, the Close must be invoked before release the batch
7845func newBatchCatFileWithCheck (ctx context.Context , repoPath string ) (* batchCatFileWithCheck , error ) {
79- batch , err := newBatch ( ctx , repoPath )
80- if err != nil {
46+ // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
47+ if err := ensureValidGitRepository ( ctx , repoPath ); err != nil {
8148 return nil , err
8249 }
8350
84- batchCheck , err := newBatchCheck (ctx , repoPath )
85- if err != nil {
86- return nil , err
87- }
51+ var batch batchCatFile
52+ batch .Writer , batch .Reader , batch .cancel = catFileBatch (ctx , repoPath , "--batch" )
53+
54+ var check batchCatFile
55+ check .Writer , check .Reader , check .cancel = catFileBatchCheck (ctx , repoPath )
8856
8957 return & batchCatFileWithCheck {
90- batch : batch ,
91- batchCheck : batchCheck ,
58+ batch : & batch ,
59+ batchCheck : & check ,
9260 }, nil
9361}
9462
@@ -125,14 +93,19 @@ type batchCommandCatFile struct {
12593 batch * batchCatFile
12694}
12795
96+ var _ Batch = & batchCommandCatFile {}
97+
12898func newBatchCommandCatFile (ctx context.Context , repoPath string ) (* batchCommandCatFile , error ) {
129- batch , err := newBatchCommand ( ctx , repoPath )
130- if err != nil {
99+ // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
100+ if err := ensureValidGitRepository ( ctx , repoPath ); err != nil {
131101 return nil , err
132102 }
133103
104+ var batch batchCatFile
105+ batch .Writer , batch .Reader , batch .cancel = catFileBatch (ctx , repoPath , "--batch-command" )
106+
134107 return & batchCommandCatFile {
135- batch : batch ,
108+ batch : & batch ,
136109 }, nil
137110}
138111
0 commit comments