Repository: moby/moby
File: daemon/containerd/image_inspect.go (Go)

Code before:
			ID:          target.Digest.String(),
			RepoTags:    repoTags,
			Descriptor:  &target,
			RepoDigests: repoDigests,
			Size:        size,
			Manifests:   manifests,
			Metadata: imagetypes.Metadata{
				LastTagTime: lastUpdated,
			},
		},
		Parent: parent, // field is deprecated with the legacy builder, but returned by the API if present.

		// GraphDriver is omitted in API v1.52 unless using a graphdriver.
		GraphDriverLegacy: &storage.DriverData{Name: i.snapshotter},
	}

	if multi.Best != nil {
		imgConfig := img.Config
		resp.Author = img.Author
		resp.Config = &imgConfig
		resp.Architecture = img.Architecture
		resp.Variant = img.Variant
		resp.Os = img.OS
		resp.OsVersion = img.OSVersion

		if len(img.History) > 0 {
			resp.Comment = img.History[len(img.History)-1].Comment
		}

		if img.Created != nil {
			resp.Created = img.Created.Format(time.RFC3339Nano)
		}

		resp.RootFS = imagetypes.RootFS{
			Type: img.RootFS.Type,
		}
		for _, layer := range img.RootFS.DiffIDs {
			resp.RootFS.Layers = append(resp.RootFS.Layers, layer.String())
		}
	}

	return resp, nil
}

func collectRepoTagsAndDigests(ctx context.Context, tagged []c8dimages.Image) (repoTags []string, repoDigests []string) {
	repoTags = make([]string, 0, len(tagged))
	repoDigests = make([]string, 0, len(tagged))
	for _, img := range tagged {
		if isDanglingImage(img) {
			if len(tagged) > 1 {
				// This is unexpected - dangling image should be deleted

Review comment (suggestion):
Could possibly move some of these together with where we construct the initial response. Did a quick try to see what it would look like; https://github.com/vvoland/moby/compare/c8d-fix-images...thaJeztah:51629_suggestions?expand=1

Code after:
			Metadata: imagetypes.Metadata{
				LastTagTime: lastUpdated,
			},
		},
		Parent: parent, // field is deprecated with the legacy builder, but returned by the API if present.

		// GraphDriver is omitted in API v1.52 unless using a graphdriver.
		GraphDriverLegacy: &storage.DriverData{Name: i.snapshotter},
	}

	var img dockerspec.DockerOCIImage
	if multi.Best != nil {
		if err := multi.Best.ReadConfig(ctx, &img); err != nil && !cerrdefs.IsNotFound(err) {
			return nil, fmt.Errorf("failed to read image config: %w", err)
		}
	}

	// Copy the config
	imgConfig := img.Config
	resp.Config = &imgConfig

	resp.Author = img.Author
	resp.Architecture = img.Architecture
	resp.Variant = img.Variant
	resp.Os = img.OS
	resp.OsVersion = img.OSVersion

	if len(img.History) > 0 {
		resp.Comment = img.History[len(img.History)-1].Comment
	}

	if img.Created != nil {
		resp.Created = img.Created.Format(time.RFC3339Nano)
	}

	resp.RootFS = imagetypes.RootFS{
		Type: img.RootFS.Type,
	}
	for _, layer := range img.RootFS.DiffIDs {
		resp.RootFS.Layers = append(resp.RootFS.Layers, layer.String())
	}

	return resp, nil
}

func collectRepoTagsAndDigests(ctx context.Context, tagged []c8dimages.Image) (repoTags []string, repoDigests []string) {
	repoTags = make([]string, 0, len(tagged))
	repoDigests = make([]string, 0, len(tagged))
	for _, img := range tagged {
		if isDanglingImage(img) {
			if len(tagged) > 1 {