Skip to content

Commit 54ddc99

Browse files
committed
Rename RowRepoIterImplementation
Signed-off-by: Javi Fontan <[email protected]>
1 parent e381330 commit 54ddc99

File tree

8 files changed

+51
-61
lines changed

8 files changed

+51
-61
lines changed

blobs.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func (r *blobsTable) TransformExpressionsUp(f func(sql.Expression) sql.Expressio
4040
func (r blobsTable) RowIter() (sql.RowIter, error) {
4141
iter := &blobIter{}
4242

43-
rowRepoIter, err := NewRowRepoIter(r.pool, iter)
43+
repoIter, err := NewRowRepoIter(r.pool, iter)
4444
if err != nil {
4545
return nil, err
4646
}
4747

48-
return rowRepoIter, nil
48+
return repoIter, nil
4949
}
5050

5151
func (blobsTable) Children() []sql.Node {
@@ -56,9 +56,7 @@ type blobIter struct {
5656
iter *object.BlobIter
5757
}
5858

59-
func (i *blobIter) NewIterator(
60-
repo *Repository) (RowRepoIterImplementation, error) {
61-
59+
func (i *blobIter) NewIterator(repo *Repository) (RowRepoIter, error) {
6260
iter, err := repo.Repo.BlobObjects()
6361
if err != nil {
6462
return nil, err

commits.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func (r *commitsTable) TransformExpressionsUp(f func(sql.Expression) sql.Express
4646
func (r commitsTable) RowIter() (sql.RowIter, error) {
4747
iter := &commitIter{}
4848

49-
rowRepoIter, err := NewRowRepoIter(r.pool, iter)
49+
repoIter, err := NewRowRepoIter(r.pool, iter)
5050
if err != nil {
5151
return nil, err
5252
}
5353

54-
return rowRepoIter, nil
54+
return repoIter, nil
5555
}
5656

5757
func (commitsTable) Children() []sql.Node {
@@ -62,9 +62,7 @@ type commitIter struct {
6262
iter object.CommitIter
6363
}
6464

65-
func (i *commitIter) NewIterator(
66-
repo *Repository) (RowRepoIterImplementation, error) {
67-
65+
func (i *commitIter) NewIterator(repo *Repository) (RowRepoIter, error) {
6866
iter, err := repo.Repo.CommitObjects()
6967
if err != nil {
7068
return nil, err

objects.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func (r *objectsTable) TransformExpressionsUp(f func(sql.Expression) sql.Express
4040
func (r objectsTable) RowIter() (sql.RowIter, error) {
4141
iter := &objectIter{}
4242

43-
rowRepoIter, err := NewRowRepoIter(r.pool, iter)
43+
repoIter, err := NewRowRepoIter(r.pool, iter)
4444
if err != nil {
4545
return nil, err
4646
}
4747

48-
return rowRepoIter, nil
48+
return repoIter, nil
4949
}
5050

5151
func (objectsTable) Children() []sql.Node {
@@ -56,9 +56,7 @@ type objectIter struct {
5656
iter *object.ObjectIter
5757
}
5858

59-
func (i *objectIter) NewIterator(
60-
repo *Repository) (RowRepoIterImplementation, error) {
61-
59+
func (i *objectIter) NewIterator(repo *Repository) (RowRepoIter, error) {
6260
iter, err := repo.Repo.Objects()
6361
if err != nil {
6462
return nil, err

references.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ func (r *referencesTable) TransformExpressionsUp(f func(sql.Expression) sql.Expr
4747
func (r referencesTable) RowIter() (sql.RowIter, error) {
4848
iter := &referenceIter{}
4949

50-
rowRepoIter, err := NewRowRepoIter(r.pool, iter)
50+
repoIter, err := NewRowRepoIter(r.pool, iter)
5151
if err != nil {
5252
return nil, err
5353
}
5454

55-
return rowRepoIter, nil
55+
return repoIter, nil
5656
}
5757

5858
func (referencesTable) Children() []sql.Node {
@@ -63,9 +63,7 @@ type referenceIter struct {
6363
iter storer.ReferenceIter
6464
}
6565

66-
func (i *referenceIter) NewIterator(
67-
repo *Repository) (RowRepoIterImplementation, error) {
68-
66+
func (i *referenceIter) NewIterator(repo *Repository) (RowRepoIter, error) {
6967
iter, err := repo.Repo.References()
7068
if err != nil {
7169
return nil, err

repository_pool.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ func (i *RepositoryIter) Close() error {
9797
return nil
9898
}
9999

100-
// RowRepoIterImplementation is the interface needed by each iterator
100+
// RowRepoIter is the interface needed by each iterator
101101
// implementation
102-
type RowRepoIterImplementation interface {
103-
NewIterator(*Repository) (RowRepoIterImplementation, error)
102+
type RowRepoIter interface {
103+
NewIterator(*Repository) (RowRepoIter, error)
104104
Next() (sql.Row, error)
105105
Close() error
106106
}
107107

108108
// RowRepoIter is used as the base to iterate over all the repositories
109109
// in the pool
110-
type RowRepoIter struct {
110+
type rowRepoIter struct {
111111
repositoryIter *RepositoryIter
112-
implementation RowRepoIterImplementation
112+
iter RowRepoIter
113113

114114
wg sync.WaitGroup
115115
done chan bool
@@ -121,47 +121,49 @@ type RowRepoIter struct {
121121
// NewRowRepoIter initializes a new repository iterator.
122122
//
123123
// * pool: is a RepositoryPool we want to iterate
124-
// * impl: implementation with RowRepoIterImplementation interface
124+
// * iter: specific RowRepoIter interface
125125
// * NewIterator: called when a new repository is about to be iterated,
126-
// returns a new RowRepoIterImplementation
126+
// returns a new RowRepoIter
127127
// * Next: called for each row
128128
// * Close: called when a repository finished iterating
129-
func NewRowRepoIter(pool *RepositoryPool,
130-
impl RowRepoIterImplementation) (*RowRepoIter, error) {
129+
func NewRowRepoIter(
130+
pool *RepositoryPool,
131+
iter RowRepoIter,
132+
) (*rowRepoIter, error) {
131133

132134
rIter, err := pool.RepoIter()
133135
if err != nil {
134136
return nil, err
135137
}
136138

137-
rowRepoIter := RowRepoIter{
139+
repoIter := rowRepoIter{
138140
repositoryIter: rIter,
139-
implementation: impl,
141+
iter: iter,
140142
done: make(chan bool),
141143
err: make(chan error),
142144
repos: make(chan *Repository),
143145
rows: make(chan sql.Row),
144146
}
145147

146-
go rowRepoIter.fillRepoChannel()
148+
go repoIter.fillRepoChannel()
147149

148150
wNum := runtime.NumCPU()
149151

150152
for i := 0; i < wNum; i++ {
151-
rowRepoIter.wg.Add(1)
153+
repoIter.wg.Add(1)
152154

153-
go rowRepoIter.rowReader(i)
155+
go repoIter.rowReader(i)
154156
}
155157

156158
go func() {
157-
rowRepoIter.wg.Wait()
158-
close(rowRepoIter.rows)
159+
repoIter.wg.Wait()
160+
close(repoIter.rows)
159161
}()
160162

161-
return &rowRepoIter, nil
163+
return &repoIter, nil
162164
}
163165

164-
func (i *RowRepoIter) fillRepoChannel() {
166+
func (i *rowRepoIter) fillRepoChannel() {
165167
for {
166168
repo, err := i.repositoryIter.Next()
167169

@@ -184,31 +186,31 @@ func (i *RowRepoIter) fillRepoChannel() {
184186
}
185187
}
186188

187-
func (i *RowRepoIter) rowReader(num int) {
189+
func (i *rowRepoIter) rowReader(num int) {
188190
defer i.wg.Done()
189191

190192
for repo := range i.repos {
191-
impl, _ := i.implementation.NewIterator(repo)
193+
iter, _ := i.iter.NewIterator(repo)
192194

193195
loop:
194196
for {
195197
select {
196198
case <-i.done:
197-
impl.Close()
199+
iter.Close()
198200
return
199201

200202
default:
201-
row, err := impl.Next()
203+
row, err := iter.Next()
202204
switch err {
203205
case nil:
204206
i.rows <- row
205207

206208
case io.EOF:
207-
impl.Close()
209+
iter.Close()
208210
break loop
209211

210212
default:
211-
impl.Close()
213+
iter.Close()
212214
i.err <- err
213215
close(i.done)
214216
return
@@ -219,7 +221,7 @@ func (i *RowRepoIter) rowReader(num int) {
219221
}
220222

221223
// Next gets the next row
222-
func (i *RowRepoIter) Next() (sql.Row, error) {
224+
func (i *rowRepoIter) Next() (sql.Row, error) {
223225
row, ok := <-i.rows
224226
if !ok {
225227
return nil, <-i.err
@@ -229,6 +231,6 @@ func (i *RowRepoIter) Next() (sql.Row, error) {
229231
}
230232

231233
// Close called to close the iterator
232-
func (i *RowRepoIter) Close() error {
233-
return i.implementation.Close()
234+
func (i *rowRepoIter) Close() error {
235+
return i.iter.Close()
234236
}

repository_pool_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ type testCommitIter struct {
137137
}
138138

139139
func (d *testCommitIter) NewIterator(
140-
repo *Repository) (RowRepoIterImplementation, error) {
141-
140+
repo *Repository,
141+
) (RowRepoIter, error) {
142142
iter, err := repo.Repo.CommitObjects()
143143
if err != nil {
144144
return nil, err
@@ -163,12 +163,12 @@ func (d *testCommitIter) Close() error {
163163
func testRepoIter(num int, require *require.Assertions, pool *RepositoryPool) {
164164
cIter := &testCommitIter{}
165165

166-
rowRepoIter, err := NewRowRepoIter(pool, cIter)
166+
repoIter, err := NewRowRepoIter(pool, cIter)
167167
require.Nil(err)
168168

169169
count := 0
170170
for {
171-
row, err := rowRepoIter.Next()
171+
row, err := repoIter.Next()
172172
if err != nil {
173173
require.Equal(io.EOF, err)
174174
break

tags.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ func (r *tagsTable) TransformExpressionsUp(f func(sql.Expression) sql.Expression
4545
func (r tagsTable) RowIter() (sql.RowIter, error) {
4646
iter := &tagIter{}
4747

48-
rowRepoIter, err := NewRowRepoIter(r.pool, iter)
48+
repoIter, err := NewRowRepoIter(r.pool, iter)
4949
if err != nil {
5050
return nil, err
5151
}
5252

53-
return rowRepoIter, nil
53+
return repoIter, nil
5454
}
5555

5656
func (tagsTable) Children() []sql.Node {
@@ -61,9 +61,7 @@ type tagIter struct {
6161
iter *object.TagIter
6262
}
6363

64-
func (i *tagIter) NewIterator(
65-
repo *Repository) (RowRepoIterImplementation, error) {
66-
64+
func (i *tagIter) NewIterator(repo *Repository) (RowRepoIter, error) {
6765
iter, err := repo.Repo.TagObjects()
6866
if err != nil {
6967
return nil, err

tree_entries.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ func (r *treeEntriesTable) TransformExpressionsUp(f func(sql.Expression) sql.Exp
4545
func (r treeEntriesTable) RowIter() (sql.RowIter, error) {
4646
iter := &treeEntryIter{}
4747

48-
rowRepoIter, err := NewRowRepoIter(r.pool, iter)
48+
repoIter, err := NewRowRepoIter(r.pool, iter)
4949
if err != nil {
5050
return nil, err
5151
}
5252

53-
return rowRepoIter, nil
53+
return repoIter, nil
5454
}
5555

5656
func (treeEntriesTable) Children() []sql.Node {
@@ -63,9 +63,7 @@ type treeEntryIter struct {
6363
t *object.Tree
6464
}
6565

66-
func (i *treeEntryIter) NewIterator(
67-
repo *Repository) (RowRepoIterImplementation, error) {
68-
66+
func (i *treeEntryIter) NewIterator(repo *Repository) (RowRepoIter, error) {
6967
iter, err := repo.Repo.TreeObjects()
7068
if err != nil {
7169
return nil, err

0 commit comments

Comments
 (0)