@@ -82,13 +82,15 @@ func NewSivaRepositoryFromPath(id, path string) (*Repository, error) {
82
82
type repository struct {
83
83
kind repoKind
84
84
path string
85
+ repo * git.Repository
85
86
}
86
87
87
88
type repoKind byte
88
89
89
90
const (
90
91
gitRepo repoKind = iota
91
92
sivaRepo
93
+ initializedrepo
92
94
)
93
95
94
96
// RepositoryPool holds a pool git repository paths and
@@ -105,14 +107,18 @@ func NewRepositoryPool() *RepositoryPool {
105
107
}
106
108
}
107
109
108
- // Add inserts a new repository in the pool
110
+ // Add inserts a new repository in the pool.
109
111
func (p * RepositoryPool ) Add (id , path string , kind repoKind ) error {
112
+ return p .add (id , repository {kind , path , nil })
113
+ }
114
+
115
+ func (p * RepositoryPool ) add (id string , repo repository ) error {
110
116
if r , ok := p .repositories [id ]; ok {
111
117
return errRepoAlreadyRegistered .New (r .path )
112
118
}
113
119
114
120
p .idOrder = append (p .idOrder , id )
115
- p .repositories [id ] = repository { kind , path }
121
+ p .repositories [id ] = repo
116
122
117
123
return nil
118
124
}
@@ -213,6 +219,11 @@ func (p *RepositoryPool) addSivaFile(root, path string, f os.FileInfo) {
213
219
}
214
220
}
215
221
222
+ // AddInitialized inserts an already initialized repository to the pool.
223
+ func (p * RepositoryPool ) AddInitialized (id string , repo * git.Repository ) error {
224
+ return p .add (id , repository {initializedrepo , "" , repo })
225
+ }
226
+
216
227
// GetPos retrieves a repository at a given position. If the position is
217
228
// out of bounds it returns io.EOF.
218
229
func (p * RepositoryPool ) GetPos (pos int ) (* Repository , error ) {
@@ -245,6 +256,8 @@ func (p *RepositoryPool) GetRepo(id string) (*Repository, error) {
245
256
repo , err = NewRepositoryFromPath (id , r .path )
246
257
case sivaRepo :
247
258
repo , err = NewSivaRepositoryFromPath (id , r .path )
259
+ case initializedrepo :
260
+ repo = NewRepository (id , r .repo )
248
261
default :
249
262
err = errInvalidRepoKind .New (r .kind )
250
263
}
0 commit comments