cli/registry/client: deprecate RepoNameForReference

This function was added in 02719bdbb5fb47389e47575bb006509da86df344, and
used newDefaultRepositoryEndpoint to get repository info for the given
image-reference.

newDefaultRepositoryEndpoint uses registry.ParseRepositoryInfo under the
hood, but the only information used from the result was the Name field,
which is set using `reference.TrimNamed(name)`. The possible error returned
was based on the domain-name of the image, and only checked for the domain
to not start, or end with a hyphen ("-").

This patch removes the use of RepoNameForReference, deprecates it, and
inlines the code used by it.

There are no known consumers of this function, so we can consider removing
it in the first possible release after this (which can be a minor release).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-03-03 15:47:02 +01:00
parent 1a165fd535
commit 6f46cd2f4b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 6 additions and 16 deletions

View File

@ -99,17 +99,10 @@ func buildPushRequest(manifests []types.ImageManifest, targetRef reference.Named
return req, err
}
targetRepoName, err := registryclient.RepoNameForReference(targetRef)
if err != nil {
return req, err
}
targetRepoName := reference.Path(reference.TrimNamed(targetRef))
for _, imageManifest := range manifests {
manifestRepoName, err := registryclient.RepoNameForReference(imageManifest.Ref)
if err != nil {
return req, err
}
manifestRepoName := reference.Path(reference.TrimNamed(imageManifest.Ref))
repoName, _ := reference.WithName(manifestRepoName)
if repoName.Name() != targetRepoName {
blobs, err := buildBlobRequestList(imageManifest, repoName)

View File

@ -103,14 +103,11 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API
return transport.NewTransport(base, modifiers...), nil
}
// RepoNameForReference returns the repository name from a reference
// RepoNameForReference returns the repository name from a reference.
//
// Deprecated: this function is no longer used and will be removed in the next release.
func RepoNameForReference(ref reference.Named) (string, error) {
// insecure is fine since this only returns the name
repo, err := newDefaultRepositoryEndpoint(ref, false)
if err != nil {
return "", err
}
return repo.Name(), nil
return reference.Path(reference.TrimNamed(ref)), nil
}
type existingTokenHandler struct {