@@ -25,15 +25,11 @@ type Repository struct {
25
25
26
26
gpgSettings * GPGSettings
27
27
28
- batchInUse bool
29
- batchCancel context.CancelFunc
30
- batchReader * bufio.Reader
31
- batchWriter WriteCloserError
28
+ batchInUse bool
29
+ batch * Batch
32
30
33
- checkInUse bool
34
- checkCancel context.CancelFunc
35
- checkReader * bufio.Reader
36
- checkWriter WriteCloserError
31
+ checkInUse bool
32
+ check * Batch
37
33
38
34
Ctx context.Context
39
35
LastCommitCache * LastCommitCache
@@ -66,52 +62,59 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
66
62
Ctx : ctx ,
67
63
}
68
64
69
- repo .batchWriter , repo . batchReader , repo .batchCancel = CatFileBatch (ctx , repoPath )
70
- repo .checkWriter , repo . checkReader , repo .checkCancel = CatFileBatchCheck (ctx , repoPath )
65
+ repo .batch = repo .NewBatch (ctx )
66
+ repo .check = repo .NewBatchCheck (ctx )
71
67
72
68
return repo , nil
73
69
}
74
70
75
71
// CatFileBatch obtains a CatFileBatch for this repository
76
72
func (repo * Repository ) CatFileBatch (ctx context.Context ) (WriteCloserError , * bufio.Reader , func ()) {
77
- if repo .batchCancel == nil || repo .batchInUse {
78
- log .Debug ("Opening temporary cat file batch for: %s" , repo .Path )
79
- return CatFileBatch (ctx , repo .Path )
73
+ if repo .batch == nil {
74
+ repo .batch = repo .NewBatch (ctx )
80
75
}
81
- repo .batchInUse = true
82
- return repo .batchWriter , repo .batchReader , func () {
83
- repo .batchInUse = false
76
+
77
+ if ! repo .batchInUse {
78
+ repo .batchInUse = true
79
+ return repo .batch .Writer , repo .batch .Reader , func () {
80
+ repo .batchInUse = false
81
+ }
84
82
}
83
+
84
+ log .Debug ("Opening temporary cat file batch for: %s" , repo .Path )
85
+ tempBatch := repo .NewBatch (ctx )
86
+ return tempBatch .Writer , tempBatch .Reader , tempBatch .Close
85
87
}
86
88
87
89
// CatFileBatchCheck obtains a CatFileBatchCheck for this repository
88
90
func (repo * Repository ) CatFileBatchCheck (ctx context.Context ) (WriteCloserError , * bufio.Reader , func ()) {
89
- if repo .checkCancel == nil || repo .checkInUse {
90
- log .Debug ("Opening temporary cat file batch-check for: %s" , repo .Path )
91
- return CatFileBatchCheck (ctx , repo .Path )
91
+ if repo .check == nil {
92
+ repo .check = repo .NewBatchCheck (ctx )
92
93
}
93
- repo .checkInUse = true
94
- return repo .checkWriter , repo .checkReader , func () {
95
- repo .checkInUse = false
94
+
95
+ if ! repo .checkInUse {
96
+ return repo .check .Writer , repo .check .Reader , func () {
97
+ repo .checkInUse = false
98
+ }
96
99
}
100
+
101
+ log .Debug ("Opening temporary cat file batch-check for: %s" , repo .Path )
102
+ tempBatchCheck := repo .NewBatchCheck (ctx )
103
+ return tempBatchCheck .Writer , tempBatchCheck .Reader , tempBatchCheck .Close
97
104
}
98
105
99
106
func (repo * Repository ) Close () error {
100
107
if repo == nil {
101
108
return nil
102
109
}
103
- if repo .batchCancel != nil {
104
- repo .batchCancel ()
105
- repo .batchReader = nil
106
- repo .batchWriter = nil
107
- repo .batchCancel = nil
110
+ if repo .batch != nil {
111
+ repo .batch .Close ()
112
+ repo .batch = nil
108
113
repo .batchInUse = false
109
114
}
110
- if repo .checkCancel != nil {
111
- repo .checkCancel ()
112
- repo .checkCancel = nil
113
- repo .checkReader = nil
114
- repo .checkWriter = nil
115
+ if repo .check != nil {
116
+ repo .check .Close ()
117
+ repo .check = nil
115
118
repo .checkInUse = false
116
119
}
117
120
repo .LastCommitCache = nil
0 commit comments