Skip to content

Commit 43b81f4

Browse files
committed
ociregistry: breaking change: rename SliceIter and ErrorIter after Seq
Iter was renamed to Seq in https://cuelang.org/cl/1177264. Update the two companion types accordingly. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I22c10bd642dbc1a48af95e6b2bf4c210998041c2 Reviewed-on: https://review.gerrithub.io/c/cue-labs/oci/+/1186137 TryBot-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent cf784f9 commit 43b81f4

File tree

8 files changed

+28
-28
lines changed

8 files changed

+28
-28
lines changed

ociregistry/func.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,19 @@ func (f *Funcs) Repositories(ctx context.Context, startAfter string) Seq[string]
178178
if f != nil && f.Repositories_ != nil {
179179
return f.Repositories_(ctx, startAfter)
180180
}
181-
return ErrorIter[string](f.newError(ctx, "Repositories", ""))
181+
return ErrorSeq[string](f.newError(ctx, "Repositories", ""))
182182
}
183183

184184
func (f *Funcs) Tags(ctx context.Context, repo string, startAfter string) Seq[string] {
185185
if f != nil && f.Tags_ != nil {
186186
return f.Tags_(ctx, repo, startAfter)
187187
}
188-
return ErrorIter[string](f.newError(ctx, "Tags", repo))
188+
return ErrorSeq[string](f.newError(ctx, "Tags", repo))
189189
}
190190

191191
func (f *Funcs) Referrers(ctx context.Context, repo string, digest Digest, artifactType string) Seq[Descriptor] {
192192
if f != nil && f.Referrers_ != nil {
193193
return f.Referrers_(ctx, repo, digest, artifactType)
194194
}
195-
return ErrorIter[Descriptor](f.newError(ctx, "Referrers", repo))
195+
return ErrorSeq[Descriptor](f.newError(ctx, "Referrers", repo))
196196
}

ociregistry/iter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func All[T any](it Seq[T]) (_ []T, _err error) {
3636
return xs, _err
3737
}
3838

39-
func SliceIter[T any](xs []T) Seq[T] {
39+
func SliceSeq[T any](xs []T) Seq[T] {
4040
return func(yield func(T, error) bool) {
4141
for _, x := range xs {
4242
if !yield(x, nil) {
@@ -46,9 +46,9 @@ func SliceIter[T any](xs []T) Seq[T] {
4646
}
4747
}
4848

49-
// ErrorIter returns an iterator that has no
49+
// ErrorSeq returns an iterator that has no
5050
// items and always returns the given error.
51-
func ErrorIter[T any](err error) Seq[T] {
51+
func ErrorSeq[T any](err error) Seq[T] {
5252
return func(yield func(T, error) bool) {
5353
yield(*new(T), err)
5454
}

ociregistry/iter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import (
99
"github.com/go-quicktest/qt"
1010
)
1111

12-
func TestSliceIter(t *testing.T) {
12+
func TestSliceSeq(t *testing.T) {
1313
slice := []int{3, 1, 4}
1414
var got []int
15-
for x, err := range SliceIter(slice) {
15+
for x, err := range SliceSeq(slice) {
1616
qt.Assert(t, qt.IsNil(err))
1717
got = append(got, x)
1818
}
1919
qt.Assert(t, qt.DeepEquals(got, slice))
2020
}
2121

22-
func TestErrorIter(t *testing.T) {
22+
func TestErrorSeq(t *testing.T) {
2323
err := errors.New("foo")
2424
i := 0
25-
for s, gotErr := range ErrorIter[string](err) {
25+
for s, gotErr := range ErrorSeq[string](err) {
2626
qt.Assert(t, qt.Equals(i, 0))
2727
qt.Assert(t, qt.Equals(s, ""))
2828
qt.Assert(t, qt.Equals(err, gotErr))

ociregistry/ociclient/lister.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ func (c *client) Referrers(ctx context.Context, repoName string, digest ociregis
7979
ListN: c.listPageSize,
8080
})
8181
if err != nil {
82-
return ociregistry.ErrorIter[ociregistry.Descriptor](err)
82+
return ociregistry.ErrorSeq[ociregistry.Descriptor](err)
8383
}
8484

8585
data, err := io.ReadAll(resp.Body)
8686
resp.Body.Close()
8787
if err != nil {
88-
return ociregistry.ErrorIter[ociregistry.Descriptor](err)
88+
return ociregistry.ErrorSeq[ociregistry.Descriptor](err)
8989
}
9090
var referrersResponse ocispec.Index
9191
if err := json.Unmarshal(data, &referrersResponse); err != nil {
92-
return ociregistry.ErrorIter[ociregistry.Descriptor](fmt.Errorf("cannot unmarshal referrers response: %v", err))
92+
return ociregistry.ErrorSeq[ociregistry.Descriptor](fmt.Errorf("cannot unmarshal referrers response: %v", err))
9393
}
94-
return ociregistry.SliceIter(referrersResponse.Manifests)
94+
return ociregistry.SliceSeq(referrersResponse.Manifests)
9595
}
9696

9797
// pager returns an iterator for a list entry point. It starts by sending the given

ociregistry/ocifilter/select.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ func (r *selectRegistry) Repositories(ctx context.Context, startAfter string) oc
168168

169169
func (r *selectRegistry) Tags(ctx context.Context, repo, startAfter string) ociregistry.Seq[string] {
170170
if !r.allow(repo) {
171-
return ociregistry.ErrorIter[string](ociregistry.ErrNameUnknown)
171+
return ociregistry.ErrorSeq[string](ociregistry.ErrNameUnknown)
172172
}
173173
return r.r.Tags(ctx, repo, startAfter)
174174
}
175175

176176
func (r *selectRegistry) Referrers(ctx context.Context, repo string, digest ociregistry.Digest, artifactType string) ociregistry.Seq[ociregistry.Descriptor] {
177177
if !r.allow(repo) {
178-
return ociregistry.ErrorIter[ociregistry.Descriptor](ociregistry.ErrNameUnknown)
178+
return ociregistry.ErrorSeq[ociregistry.Descriptor](ociregistry.ErrNameUnknown)
179179
}
180180
return r.r.Referrers(ctx, repo, digest, artifactType)
181181
}

ociregistry/ocimem/lister.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (r *Registry) Tags(ctx context.Context, repoName string, startAfter string)
3232
defer r.mu.Unlock()
3333
repo, err := r.repo(repoName)
3434
if err != nil {
35-
return ociregistry.ErrorIter[string](err)
35+
return ociregistry.ErrorSeq[string](err)
3636
}
3737
return mapKeysIter(repo.tags, stringLess, startAfter)
3838
}
@@ -42,7 +42,7 @@ func (r *Registry) Referrers(ctx context.Context, repoName string, digest ocireg
4242
defer r.mu.Unlock()
4343
repo, err := r.repo(repoName)
4444
if err != nil {
45-
return ociregistry.ErrorIter[ociregistry.Descriptor](err)
45+
return ociregistry.ErrorSeq[ociregistry.Descriptor](err)
4646
}
4747
var referrers []ociregistry.Descriptor
4848
for _, b := range repo.manifests {
@@ -55,7 +55,7 @@ func (r *Registry) Referrers(ctx context.Context, repoName string, digest ocireg
5555
sort.Slice(referrers, func(i, j int) bool {
5656
return descriptorLess(referrers[i], referrers[j])
5757
})
58-
return ociregistry.SliceIter(referrers)
58+
return ociregistry.SliceSeq(referrers)
5959
}
6060

6161
func mapKeysIter[K comparable, V any](m map[K]V, less func(K, K) bool, startAfter K) ociregistry.Seq[K] {
@@ -68,7 +68,7 @@ func mapKeysIter[K comparable, V any](m map[K]V, less func(K, K) bool, startAfte
6868
sort.Slice(ks, func(i, j int) bool {
6969
return less(ks[i], ks[j])
7070
})
71-
return ociregistry.SliceIter(ks)
71+
return ociregistry.SliceSeq(ks)
7272
}
7373

7474
func stringLess(s1, s2 string) bool {

ociregistry/ociunify/iter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ var mergeIterTests = []struct {
2828
wantErr error
2929
}{{
3030
testName: "IdenticalContents",
31-
it0: ociregistry.SliceIter([]int{1, 2, 3}),
32-
it1: ociregistry.SliceIter([]int{1, 2, 3}),
31+
it0: ociregistry.SliceSeq([]int{1, 2, 3}),
32+
it1: ociregistry.SliceSeq([]int{1, 2, 3}),
3333
want: []int{1, 2, 3},
3434
}, {
3535
testName: "DifferentContents",
36-
it0: ociregistry.SliceIter([]int{0, 1, 2, 3}),
37-
it1: ociregistry.SliceIter([]int{1, 2, 3, 5}),
36+
it0: ociregistry.SliceSeq([]int{0, 1, 2, 3}),
37+
it1: ociregistry.SliceSeq([]int{1, 2, 3, 5}),
3838
want: []int{0, 1, 2, 3, 5},
3939
}, {
4040
testName: "NoItems",
41-
it0: ociregistry.SliceIter[int](nil),
42-
it1: ociregistry.SliceIter[int](nil),
41+
it0: ociregistry.SliceSeq[int](nil),
42+
it1: ociregistry.SliceSeq[int](nil),
4343
want: []int{},
4444
}}
4545

ociregistry/ociunify/lister.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func mergeIter[T any](it0, it1 ociregistry.Seq[T], cmp func(T, T) int) ociregist
5656
notFound0 := errors.Is(err0, ociregistry.ErrNameUnknown)
5757
notFound1 := errors.Is(err1, ociregistry.ErrNameUnknown)
5858
if notFound0 && notFound1 {
59-
return ociregistry.ErrorIter[T](err0)
59+
return ociregistry.ErrorSeq[T](err0)
6060
}
6161
if notFound0 {
6262
err0 = nil
@@ -87,7 +87,7 @@ func mergeIter[T any](it0, it1 ociregistry.Seq[T], cmp func(T, T) int) ociregist
8787
err = err1
8888
}
8989
if err == nil {
90-
return ociregistry.SliceIter(xs)
90+
return ociregistry.SliceSeq(xs)
9191
}
9292
return func(yield func(T, error) bool) {
9393
for _, x := range xs {

0 commit comments

Comments
 (0)