@@ -25,15 +25,11 @@ type Repository struct {
2525
2626 gpgSettings * GPGSettings
2727
28- batchInUse bool
29- batchCancel context.CancelFunc
30- batchReader * bufio.Reader
31- batchWriter WriteCloserError
28+ batchInUse bool
29+ batch * Batch
3230
33- checkInUse bool
34- checkCancel context.CancelFunc
35- checkReader * bufio.Reader
36- checkWriter WriteCloserError
31+ checkInUse bool
32+ check * Batch
3733
3834 Ctx context.Context
3935 LastCommitCache * LastCommitCache
@@ -55,63 +51,75 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
5551 return nil , util .NewNotExistErrorf ("no such file or directory" )
5652 }
5753
58- // 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!
59- if err := EnsureValidGitRepository (ctx , repoPath ); err != nil {
60- return nil , err
61- }
62-
63- repo := & Repository {
54+ return & Repository {
6455 Path : repoPath ,
6556 tagCache : newObjectCache (),
6657 Ctx : ctx ,
67- }
68-
69- repo .batchWriter , repo .batchReader , repo .batchCancel = CatFileBatch (ctx , repoPath )
70- repo .checkWriter , repo .checkReader , repo .checkCancel = CatFileBatchCheck (ctx , repoPath )
71-
72- return repo , nil
58+ }, nil
7359}
7460
7561// CatFileBatch obtains a CatFileBatch for this repository
76- 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 )
62+ func (repo * Repository ) CatFileBatch (ctx context.Context ) (WriteCloserError , * bufio.Reader , func (), error ) {
63+ if repo .batch == nil {
64+ var err error
65+ repo .batch , err = repo .NewBatch (ctx )
66+ if err != nil {
67+ return nil , nil , nil , err
68+ }
8069 }
81- repo .batchInUse = true
82- return repo .batchWriter , repo .batchReader , func () {
83- repo .batchInUse = false
70+
71+ if ! repo .batchInUse {
72+ repo .batchInUse = true
73+ return repo .batch .Writer , repo .batch .Reader , func () {
74+ repo .batchInUse = false
75+ }, nil
8476 }
77+
78+ log .Debug ("Opening temporary cat file batch for: %s" , repo .Path )
79+ tempBatch , err := repo .NewBatch (ctx )
80+ if err != nil {
81+ return nil , nil , nil , err
82+ }
83+ return tempBatch .Writer , tempBatch .Reader , tempBatch .Close , nil
8584}
8685
8786// CatFileBatchCheck obtains a CatFileBatchCheck for this repository
88- 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 )
87+ func (repo * Repository ) CatFileBatchCheck (ctx context.Context ) (WriteCloserError , * bufio.Reader , func (), error ) {
88+ if repo .check == nil {
89+ var err error
90+ repo .check , err = repo .NewBatchCheck (ctx )
91+ if err != nil {
92+ return nil , nil , nil , err
93+ }
9294 }
93- repo .checkInUse = true
94- return repo .checkWriter , repo .checkReader , func () {
95- repo .checkInUse = false
95+
96+ if ! repo .checkInUse {
97+ repo .checkInUse = true
98+ return repo .check .Writer , repo .check .Reader , func () {
99+ repo .checkInUse = false
100+ }, nil
101+ }
102+
103+ log .Debug ("Opening temporary cat file batch-check for: %s" , repo .Path )
104+ tempBatchCheck , err := repo .NewBatchCheck (ctx )
105+ if err != nil {
106+ return nil , nil , nil , err
96107 }
108+ return tempBatchCheck .Writer , tempBatchCheck .Reader , tempBatchCheck .Close , nil
97109}
98110
99111func (repo * Repository ) Close () error {
100112 if repo == nil {
101113 return nil
102114 }
103- if repo .batchCancel != nil {
104- repo .batchCancel ()
105- repo .batchReader = nil
106- repo .batchWriter = nil
107- repo .batchCancel = nil
115+ if repo .batch != nil {
116+ repo .batch .Close ()
117+ repo .batch = nil
108118 repo .batchInUse = false
109119 }
110- if repo .checkCancel != nil {
111- repo .checkCancel ()
112- repo .checkCancel = nil
113- repo .checkReader = nil
114- repo .checkWriter = nil
120+ if repo .check != nil {
121+ repo .check .Close ()
122+ repo .check = nil
115123 repo .checkInUse = false
116124 }
117125 repo .LastCommitCache = nil
0 commit comments