Skip to content

Commit f65934a

Browse files
committed
gitbase/repository_pool: support initialized repos
Signed-off-by: Javi Fontan <[email protected]>
1 parent 1b58c30 commit f65934a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

repository_pool.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ func NewSivaRepositoryFromPath(id, path string) (*Repository, error) {
8282
type repository struct {
8383
kind repoKind
8484
path string
85+
repo *git.Repository
8586
}
8687

8788
type repoKind byte
8889

8990
const (
9091
gitRepo repoKind = iota
9192
sivaRepo
93+
initializedrepo
9294
)
9395

9496
// RepositoryPool holds a pool git repository paths and
@@ -105,14 +107,18 @@ func NewRepositoryPool() *RepositoryPool {
105107
}
106108
}
107109

108-
// Add inserts a new repository in the pool
110+
// Add inserts a new repository in the pool.
109111
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 {
110116
if r, ok := p.repositories[id]; ok {
111117
return errRepoAlreadyRegistered.New(r.path)
112118
}
113119

114120
p.idOrder = append(p.idOrder, id)
115-
p.repositories[id] = repository{kind, path}
121+
p.repositories[id] = repo
116122

117123
return nil
118124
}
@@ -213,6 +219,11 @@ func (p *RepositoryPool) addSivaFile(root, path string, f os.FileInfo) {
213219
}
214220
}
215221

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+
216227
// GetPos retrieves a repository at a given position. If the position is
217228
// out of bounds it returns io.EOF.
218229
func (p *RepositoryPool) GetPos(pos int) (*Repository, error) {
@@ -245,6 +256,8 @@ func (p *RepositoryPool) GetRepo(id string) (*Repository, error) {
245256
repo, err = NewRepositoryFromPath(id, r.path)
246257
case sivaRepo:
247258
repo, err = NewSivaRepositoryFromPath(id, r.path)
259+
case initializedrepo:
260+
repo = NewRepository(id, r.repo)
248261
default:
249262
err = errInvalidRepoKind.New(r.kind)
250263
}

0 commit comments

Comments
 (0)