Skip to content

Commit 43a406c

Browse files
committed
gitbase/repository_pool: move billyRepository to test file
Signed-off-by: Javi Fontan <[email protected]>
1 parent 28499ea commit 43a406c

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

fs_error_test.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ func setupErrorRepos(t *testing.T) (*sql.Context, CleanupFunc) {
6060

6161
fs, err := brokenFS(brokenPackfile, baseFS)
6262
require.NoError(err)
63-
pool.AddBilly("packfile", fs)
63+
pool.Add(billyRepo("packfile", fs))
6464

6565
fs, err = brokenFS(brokenIndex, baseFS)
6666
require.NoError(err)
67-
pool.AddBilly("index", fs)
67+
pool.Add(billyRepo("index", fs))
6868

6969
fs, err = brokenFS(0, baseFS)
7070
require.NoError(err)
71-
pool.AddBilly("ok", fs)
71+
pool.Add(billyRepo("ok", fs))
7272

7373
session := NewSession(pool, WithSkipGitErrors(true))
7474
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
@@ -141,6 +141,41 @@ func testTable(t *testing.T, tableName string, number int) {
141141
}
142142
}
143143

144+
type billyRepository struct {
145+
id string
146+
fs billy.Filesystem
147+
}
148+
149+
func billyRepo(id string, fs billy.Filesystem) repository {
150+
return &billyRepository{id, fs}
151+
}
152+
153+
func (r *billyRepository) ID() string {
154+
return r.id
155+
}
156+
157+
func (r *billyRepository) Repo() (*Repository, error) {
158+
storage, err := filesystem.NewStorage(r.fs)
159+
if err != nil {
160+
return nil, err
161+
}
162+
163+
repo, err := git.Open(storage, r.fs)
164+
if err != nil {
165+
return nil, err
166+
}
167+
168+
return NewRepository(r.id, repo), nil
169+
}
170+
171+
func (r *billyRepository) FS() (billy.Filesystem, error) {
172+
return r.fs, nil
173+
}
174+
175+
func (r *billyRepository) Path() string {
176+
return r.id
177+
}
178+
144179
type brokenType uint64
145180

146181
const (

repository_pool.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -146,41 +146,6 @@ func (r *sivaRepository) Path() string {
146146
return r.path
147147
}
148148

149-
type billyRepository struct {
150-
id string
151-
fs billy.Filesystem
152-
}
153-
154-
func billyRepo(id string, fs billy.Filesystem) repository {
155-
return &billyRepository{id, fs}
156-
}
157-
158-
func (r *billyRepository) ID() string {
159-
return r.id
160-
}
161-
162-
func (r *billyRepository) Repo() (*Repository, error) {
163-
storage, err := filesystem.NewStorage(r.fs)
164-
if err != nil {
165-
return nil, err
166-
}
167-
168-
repo, err := git.Open(storage, r.fs)
169-
if err != nil {
170-
return nil, err
171-
}
172-
173-
return NewRepository(r.id, repo), nil
174-
}
175-
176-
func (r *billyRepository) FS() (billy.Filesystem, error) {
177-
return r.fs, nil
178-
}
179-
180-
func (r *billyRepository) Path() string {
181-
return r.id
182-
}
183-
184149
// RepositoryPool holds a pool git repository paths and
185150
// functionality to open and iterate them.
186151
type RepositoryPool struct {
@@ -304,11 +269,6 @@ func (p *RepositoryPool) addSivaFile(root, path string, f os.FileInfo) {
304269
}
305270
}
306271

307-
// AddBilly inserts a billy filesystem containing a git repo to the pool.
308-
func (p *RepositoryPool) AddBilly(id string, fs billy.Filesystem) error {
309-
return p.Add(billyRepo(id, fs))
310-
}
311-
312272
// GetPos retrieves a repository at a given position. If the position is
313273
// out of bounds it returns io.EOF.
314274
func (p *RepositoryPool) GetPos(pos int) (*Repository, error) {

0 commit comments

Comments
 (0)