Skip to content

Commit 2ce94e4

Browse files
committed
internal/registryclient: repositoryEndpoint: memoize repoName
- Parse/format the repository name when constructing and store the result. - Remove the Name() accessor, as this type is only used internally, and no longer had any special handling. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b2b7187 commit 2ce94e4

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

internal/registryclient/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest
120120
}
121121

122122
func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) {
123-
repoName, err := reference.WithName(repoEndpoint.Name())
123+
repoName, err := reference.WithName(repoEndpoint.repoName)
124124
if err != nil {
125125
return nil, fmt.Errorf("failed to parse repo name from %s: %w", ref, err)
126126
}
@@ -148,7 +148,7 @@ func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoi
148148
httpTransport, err := getHTTPTransport(
149149
c.authConfigResolver(ctx, repoEndpoint.indexInfo),
150150
repoEndpoint.endpoint,
151-
repoEndpoint.Name(),
151+
repoEndpoint.repoName,
152152
c.userAgent,
153153
repoEndpoint.actions,
154154
)

internal/registryclient/endpoint.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,19 @@ import (
1616
)
1717

1818
type repositoryEndpoint struct {
19-
repoName reference.Named
19+
repoName string
2020
indexInfo *registrytypes.IndexInfo
2121
endpoint registry.APIEndpoint
2222
actions []string
2323
}
2424

25-
// Name returns the repository name
26-
func (r repositoryEndpoint) Name() string {
27-
return reference.Path(r.repoName)
28-
}
29-
3025
// BaseURL returns the endpoint url
3126
func (r repositoryEndpoint) BaseURL() string {
3227
return r.endpoint.URL.String()
3328
}
3429

3530
func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) {
36-
repoName := reference.TrimNamed(ref)
3731
indexInfo := registry.NewIndexInfo(ref)
38-
3932
endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure)
4033
if err != nil {
4134
return repositoryEndpoint{}, err
@@ -44,7 +37,7 @@ func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositor
4437
endpoint.TLSConfig.InsecureSkipVerify = true
4538
}
4639
return repositoryEndpoint{
47-
repoName: repoName,
40+
repoName: reference.Path(reference.TrimNamed(ref)),
4841
indexInfo: indexInfo,
4942
endpoint: endpoint,
5043
}, nil

internal/registryclient/fetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named,
221221
return err
222222
}
223223

224-
repoName := reference.TrimNamed(namedRef)
224+
repoName := reference.Path(reference.TrimNamed(namedRef))
225225
indexInfo := registry.NewIndexInfo(namedRef)
226226

227227
confirmedTLSRegistries := make(map[string]bool)

0 commit comments

Comments
 (0)