aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2018-07-27 03:20:25 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-01 18:22:58 +0000
commit0ef38ba07971ea9921a98353789fdb5655e65c10 (patch)
tree33f5e7ce88ccdfa2cd5fbc9fccf3e6d3fcab9b52
parentecc1db39b53e0566aed7de7192db916cf44a9fcb (diff)
downloadpodman-0ef38ba07971ea9921a98353789fdb5655e65c10.tar.gz
podman-0ef38ba07971ea9921a98353789fdb5655e65c10.tar.bz2
podman-0ef38ba07971ea9921a98353789fdb5655e65c10.zip
Return early in refNamesFromImageReference instead of appending to pullNames
Almost all paths appended to pullNames exactly once; just construct a single-element array in place and return it. That way we can add empty lines as separators, and still come out shorter. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1176 Approved by: rhatdan
-rw-r--r--libpod/image/pull.go50
1 files changed, 24 insertions, 26 deletions
diff --git a/libpod/image/pull.go b/libpod/image/pull.go
index b17b4434d..2b3f70441 100644
--- a/libpod/image/pull.go
+++ b/libpod/image/pull.go
@@ -86,8 +86,6 @@ func getPullRefName(srcRef types.ImageReference, destName string) *pullRefName {
// refNamesFromImageReference returns a list of pullRefName for a single ImageReference, depending on the used transport.
func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference, imgName string, sc *types.SystemContext) ([]*pullRefName, error) {
- var pullNames []*pullRefName
-
// supports pulling from docker-archive, oci, and registries
switch srcRef.Transport().Name() {
case DockerArchive:
@@ -108,26 +106,28 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference
if err != nil {
return nil, err
}
- pullInfo := getPullRefName(srcRef, reference)
- pullNames = append(pullNames, pullInfo)
+ return []*pullRefName{getPullRefName(srcRef, reference)}, nil
+ }
+
+ var dest []string
+ if len(manifest[0].RepoTags) > 0 {
+ dest = append(dest, manifest[0].RepoTags...)
} else {
- var dest []string
- if len(manifest[0].RepoTags) > 0 {
- dest = append(dest, manifest[0].RepoTags...)
- } else {
- // If the input image has no repotags, we need to feed it a dest anyways
- digest, err := getImageDigest(ctx, srcRef, sc)
- if err != nil {
- return nil, err
- }
- dest = append(dest, digest)
- }
- // Need to load in all the repo tags from the manifest
- for _, dst := range dest {
- pullInfo := getPullRefName(srcRef, dst)
- pullNames = append(pullNames, pullInfo)
+ // If the input image has no repotags, we need to feed it a dest anyways
+ digest, err := getImageDigest(ctx, srcRef, sc)
+ if err != nil {
+ return nil, err
}
+ dest = append(dest, digest)
}
+ // Need to load in all the repo tags from the manifest
+ res := []*pullRefName{}
+ for _, dst := range dest {
+ pullInfo := getPullRefName(srcRef, dst)
+ res = append(res, pullInfo)
+ }
+ return res, nil
+
case OCIArchive:
// retrieve the manifest from index.json to access the image name
manifest, err := ociarchive.LoadManifestDescriptor(srcRef)
@@ -146,8 +146,8 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference
} else {
dest = manifest.Annotations["org.opencontainers.image.ref.name"]
}
- pullInfo := getPullRefName(srcRef, dest)
- pullNames = append(pullNames, pullInfo)
+ return []*pullRefName{getPullRefName(srcRef, dest)}, nil
+
case DirTransport:
path := srcRef.StringWithinTransport()
image := path
@@ -157,13 +157,11 @@ func refNamesFromImageReference(ctx context.Context, srcRef types.ImageReference
// so docker.io isn't prepended, and the path becomes the repository
image = DefaultLocalRepo + image
}
- pullInfo := getPullRefName(srcRef, image)
- pullNames = append(pullNames, pullInfo)
+ return []*pullRefName{getPullRefName(srcRef, image)}, nil
+
default:
- pullInfo := getPullRefName(srcRef, imgName)
- pullNames = append(pullNames, pullInfo)
+ return []*pullRefName{getPullRefName(srcRef, imgName)}, nil
}
- return pullNames, nil
}
// refPairsFromImageReference returns a list of pullRefPair for a single ImageReference, depending on the used transport.