// imageWithDigestString takes an image string and a digest, and updates
// the image string if it didn't originally contain a digest. It returns
// an empty string if there are no updates.
181119
func imageWithDigestString(image string, dgst digest.Digest) string {
	namedRef, err := reference.ParseNormalizedNamed(image)
	if err == nil {
		if _, isCanonical := namedRef.(reference.Canonical); !isCanonical {
			// ensure that image gets a default tag if none is provided
			img, err := reference.WithDigest(namedRef, dgst)
			if err == nil {
				return reference.FamiliarString(img)
			}
		}
	}
	return ""
}
1256116
func WithImageService(imageService imagesapi.ImagesClient) ServicesOpt {
	return func(s *services) {
		s.imageStore = NewImageStoreFromClient(imageService)
	}
}
802546
func (t *CarouselTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType) *CarouselTemplate {
	t.ImageAspectRatio = imageAspectRatio
	t.ImageSize = imageSize
	return t
}
600702
func DigestOrImageMatch(image, imageID string) bool {
	if d, err := digest.ParseDigest(image); err == nil {
		return strings.HasPrefix(d.Hex(), imageID) || strings.HasPrefix(image, imageID)
	}
	return strings.HasPrefix(image, imageID)
}
1196678
func (dh *Client) PushImage(name string, opts *PushImageOptions) error {
	if name == "" {
		return fmt.Errorf("no image name given")
	}

	if opts == nil {
		opts = &PushImageOptions{Callback: HandlePullImageMessage}
	}

	registry, image, tag := splitImageName(name)
	if registry == "" {
		return fmt.Errorf("no registry given")
	}

	buf := &bytes.Buffer{}
	buf.WriteString(FAKE_AUTH)
	url := dh.Address + "/images/" + registry + "/" + image + "/push?tag=" + tag

	rsp, e := dh.postWithReader(url, buf)
	if e != nil {
		return e
	}
	defer rsp.Body.Close()

	return handleJSONStream(rsp.Body, opts.Callback)
}
1222882
func ParseQueryString(param string, req *http.Request, params imageserver.Params) {
	s := req.URL.Query().Get(param)
	if s != "" {
		params.Set(param, s)
	}
}
506571
func parseTag(s string) (prefix, tag string, err error) {
	splitString := strings.Split(s, ":")
	if len(splitString) == 1 {
		prefix = splitString[0]
	} else if len(splitString) == 2 {
		prefix, tag = splitString[0], splitString[1]
	} else {
		// Unlikely edge case but it doesn't hurt to test for it.
		return "", "", fmt.Errorf("Path should not contain more than one colon: %q", s)
	}

	if strings.HasSuffix(prefix, "/") {
		return "", "", fmt.Errorf(`Image name must not have a trailing "/": %s`, prefix)
	}

	return prefix, tag, nil
}
1038184
func WithDigestRef(f func(digest.Digest) string) ImportOpt {
	return func(c *importOpts) error {
		c.dgstRefT = f
		return nil
	}
}
969707
func WithDigest(name Named, digest digest.Digest) (Canonical, error) {
	r, err := reference.WithDigest(name, digest)
	if err != nil {
		return nil, err
	}
	return &canonicalRef{namedRef{r}}, nil
}
1190652
func (e *Engine) ImageLocalDigests(ctx context.Context, image string) ([]string, error) {
	inspect, _, err := e.client.ImageInspectWithRaw(ctx, image)
	if err != nil {
		return nil, err
	}
	return inspect.RepoDigests, nil
}
513153
func ServiceWithImage(image string) func(*swarmtypes.ServiceSpec) {
	return func(spec *swarmtypes.ServiceSpec) {
		ensureContainerSpec(spec)
		spec.TaskTemplate.ContainerSpec.Image = image
	}
}
1165119
func Decode(in string) (image Image, err error) {
	repo, tag := parseRepositoryTag(in)
	image.Registry, image.Repository = splitRepository(repo)

	if strings.Contains(tag, ":") {
		image.Digest = tag
	} else {
		image.Tag = tag
	}

	if image.Repository == "" {
		err = ErrInvalidImage
		return
	}

	return
}
17354
func NewDigest(chall string) (*Digest, error) {
	c, err := parseChallenge(chall)
	if err != nil {
		return nil, err
	}
	return &Digest{
		Realm:      c.Realm,
		Nonce:      c.Nonce,
		Algorithm:  c.Algorithm,
		Opaque:     c.Opaque,
		Qop:        c.Qop,
		NonceCount: 1,
		m:          &sync.Mutex{},
	}, nil
}
831076
func GetDigestByNid(nid NID) (*Digest, error) {
	sn, err := Nid2ShortName(nid)
	if err != nil {
		return nil, err
	}
	return GetDigestByName(sn)
}
1053209
func WithDigest(name Named, digest digest.Digest) (Canonical, error) {
	if !anchoredDigestRegexp.MatchString(digest.String()) {
		return nil, ErrDigestInvalidFormat
	}
	if tagged, ok := name.(Tagged); ok {
		return reference{
			name:   name.Name(),
			tag:    tagged.Tag(),
			digest: digest,
		}, nil
	}
	return canonicalReference{
		name:   name.Name(),
		digest: digest,
	}, nil
}
465233
func loadClientDigests(path string) (*digests.ClientDigestsFile, error) {
	switch f, err := os.Open(path); {
	case os.IsNotExist(err):
		base := filepath.Base(path)
		return nil, fmt.Errorf("the file with pinned client hashes (%s) doesn't exist, "+
			"use 'cipd selfupdate-roll -version-file %s' to generate it",
			base, strings.TrimSuffix(base, digestsSfx))
	case err != nil:
		return nil, err
	default:
		defer f.Close()
		return digests.ParseClientDigestsFile(f)
	}
}
1075260
func (dig2f digestToFilterMapping) String() string {
	var buffer bytes.Buffer
	collection2TxID := make(map[string][]string)
	for dig := range dig2f {
		collection2TxID[dig.Collection] = append(collection2TxID[dig.Collection], dig.TxId)
	}
	for col, txIDs := range collection2TxID {
		buffer.WriteString(fmt.Sprintf("{%s: %v}", col, txIDs))
	}
	return buffer.String()
}