<commit_before>package docker

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"path/filepath"
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/docker/distribution/digest"
	"github.com/docker/distribution/manifest/manifestlist"
	"github.com/docker/distribution/registry/api/v2"
	"github.com/docker/distribution/registry/client/auth"
	"github.com/docker/distribution/registry/client/transport"
	"github.com/go-yaml/yaml"

	"github.com/docker/docker/dockerversion"
	"github.com/docker/docker/opts"
	"github.com/docker/docker/reference"
	"github.com/docker/docker/registry"
)

// YAMLInput represents the YAML format input to the pushml
// command.
type YAMLInput struct {
	Image     string
	Manifests []ManifestEntry
}

// ManifestEntry represents an entry in the list of manifests to
// be combined into a manifest list, provided via the YAML input
type ManifestEntry struct {
	Image    string
	Platform manifestlist.PlatformSpec
}

func PutManifestList(c *cli.Context, filePath string) (string, error) {
	var (
		yamlInput    YAMLInput
		manifestList manifestlist.ManifestList
	)

	filename, err := filepath.Abs(filePath)
	if err != nil {
		return "", fmt.Errorf("Can't resolve path to %q: %v", filePath, err)
	}
	yamlFile, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", fmt.Errorf("Can't read YAML file %q: %v", filePath, err)
	}
	err = yaml.Unmarshal(yamlFile, &yamlInput)
	if err != nil {
		return "", fmt.Errorf("Can't unmarshal YAML file %q: %v", filePath, err)
	}

	// Set the schema version
	manifestList.Versioned = manifestlist.SchemaVersion

	logrus.Info("Retrieving digests of images...")
	for _, img := range yamlInput.Manifests {
		// validate os/arch input
		if !isValidOSArch(img.Platform.OS, img.Platform.Architecture) {
			return "", fmt.Errorf("Manifest entry for image %s has unsupported os/arch combination: %s/%s", img.Image, img.Platform.OS, img.Platform.Architecture)
		}
		imgsInsp, err := GetData(c, img.Image)
		if len(imgsInsp) > 1 {
			// too many responses--can only happen if a manifest list was returned for the name lookup
			return "", fmt.Errorf("You specified a manifest list entry from a digest that points to a current manifest list. Manifest lists do not allow recursion.")
		}
		imgInsp := imgsInsp[0]
		if err != nil {
			return "", fmt.Errorf("Inspect of image %q failed with error: %v", img.Image, err)
		}

		manifest := manifestlist.ManifestDescriptor{
			Platform: img.Platform,
		}
		manifest.Descriptor.Digest, err = digest.ParseDigest(imgInsp.Digest)
		manifest.Size = imgInsp.Size
		manifest.MediaType = imgInsp.MediaType

		if err != nil {
			return "", fmt.Errorf("Digest parse of image %q failed with error: %v", img.Image, err)
		}
		logrus.Infof("Image %q is digest %s; size: %d", img.Image, imgInsp.Digest, imgInsp.Size)
		manifestList.Manifests = append(manifestList.Manifests, manifest)
	}

	// process the final image name reference for the manifest list
	ref, err := reference.ParseNamed(yamlInput.Image)
	if err != nil {
		return "", fmt.Errorf("Error parsing name for manifest list (%s): %v", yamlInput.Image, err)
	}
	repoInfo, err := registry.ParseRepositoryInfo(ref)
	if err != nil {
		return "", fmt.Errorf("Error parsing repository name for manifest list (%s): %v", yamlInput.Image, err)
	}

	options := &registry.Options{}<commit_msg>Correct error path and better var names<commit_after>package docker

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"path/filepath"
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/docker/distribution/digest"
	"github.com/docker/distribution/manifest/manifestlist"
	"github.com/docker/distribution/registry/api/v2"
	"github.com/docker/distribution/registry/client/auth"
	"github.com/docker/distribution/registry/client/transport"
	"github.com/go-yaml/yaml"

	"github.com/docker/docker/dockerversion"
	"github.com/docker/docker/opts"
	"github.com/docker/docker/reference"
	"github.com/docker/docker/registry"
)

// YAMLInput represents the YAML format input to the pushml
// command.
type YAMLInput struct {
	Image     string
	Manifests []ManifestEntry
}

// ManifestEntry represents an entry in the list of manifests to
// be combined into a manifest list, provided via the YAML input
type ManifestEntry struct {
	Image    string
	Platform manifestlist.PlatformSpec
}

func PutManifestList(c *cli.Context, filePath string) (string, error) {
	var (
		yamlInput    YAMLInput
		manifestList manifestlist.ManifestList
	)

	filename, err := filepath.Abs(filePath)
	if err != nil {
		return "", fmt.Errorf("Can't resolve path to %q: %v", filePath, err)
	}
	yamlFile, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", fmt.Errorf("Can't read YAML file %q: %v", filePath, err)
	}
	err = yaml.Unmarshal(yamlFile, &yamlInput)
	if err != nil {
		return "", fmt.Errorf("Can't unmarshal YAML file %q: %v", filePath, err)
	}

	// Set the schema version
	manifestList.Versioned = manifestlist.SchemaVersion

	logrus.Info("Retrieving digests of images...")
	for _, img := range yamlInput.Manifests {
		// validate os/arch input
		if !isValidOSArch(img.Platform.OS, img.Platform.Architecture) {
			return "", fmt.Errorf("Manifest entry for image %s has unsupported os/arch combination: %s/%s", img.Image, img.Platform.OS, img.Platform.Architecture)
		}
		mfstData, err := GetData(c, img.Image)
		if err != nil {
			return "", fmt.Errorf("Inspect of image %q failed with error: %v", img.Image, err)
		}
		if len(mfstData) > 1 {
			// too many responses--can only happen if a manifest list was returned for the name lookup
			return "", fmt.Errorf("You specified a manifest list entry from a digest that points to a current manifest list. Manifest lists do not allow recursion.")
		}
		// the non-manifest list case will always have exactly one manifest response
		imgMfst := mfstData[0]

		manifest := manifestlist.ManifestDescriptor{
			Platform: img.Platform,
		}
		manifest.Descriptor.Digest, err = digest.ParseDigest(imgMfst.Digest)
		manifest.Size = imgMfst.Size
		manifest.MediaType = imgMfst.MediaType

		if err != nil {
			return "", fmt.Errorf("Digest parse of image %q failed with error: %v", img.Image, err)
		}
		logrus.Infof("Image %q is digest %s; size: %d", img.Image, imgMfst.Digest, imgMfst.Size)
		manifestList.Manifests = append(manifestList.Manifests, manifest)
	}

	// process the final image name reference for the manifest list
	ref, err := reference.ParseNamed(yamlInput.Image)
	if err != nil {
		return "", fmt.Errorf("Error parsing name for manifest list (%s): %v", yamlInput.Image, err)
	}
	repoInfo, err := registry.ParseRepositoryInfo(ref)
	if err != nil {
		return "", fmt.Errorf("Error parsing repository name for manifest list (%s): %v", yamlInput.Image, err)
	}

	options := &registry.Options{}
{'fraction_non_alphanumeric': 0.12498168498168498, 'fraction_numerical': 0.0008791208791208791, 'mean_word_length': 4.16338880484115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7442238', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2206, 'n_words': 626}