@@ -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
@@ -55,63 +51,75 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
55
51
return nil , util .NewNotExistErrorf ("no such file or directory" )
56
52
}
57
53
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 {
64
55
Path : repoPath ,
65
56
tagCache : newObjectCache (),
66
57
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
73
59
}
74
60
75
61
// 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
+ }
80
69
}
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
84
76
}
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
85
84
}
86
85
87
86
// 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
+ }
92
94
}
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
96
107
}
108
+ return tempBatchCheck .Writer , tempBatchCheck .Reader , tempBatchCheck .Close , nil
97
109
}
98
110
99
111
func (repo * Repository ) Close () error {
100
112
if repo == nil {
101
113
return nil
102
114
}
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
108
118
repo .batchInUse = false
109
119
}
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
115
123
repo .checkInUse = false
116
124
}
117
125
repo .LastCommitCache = nil
0 commit comments