// NewProviderLock creates a new ProviderLock object that isn't associated
// with any Locks object.
//
// This is here primarily for testing. Most callers should use Locks.SetProvider
// to construct a new provider lock and insert it into a Locks object at the
// same time.
//
// The ownership of the backing array for the slice of hashes passes to this
// function, and so the caller must not read or write that backing array after
// calling NewProviderLock.
//
// Only lockable providers can be passed to this method. If you pass a
// non-lockable provider address then this function will panic. Use
// function ProviderIsLockable to determine whether a particular provider
// should participate in the version locking mechanism.
NewProviderLock creates a new ProviderLock object that isn't associated
with any Locks object.

This is here primarily for testing. Most callers should use Locks.SetProvider
to construct a new provider lock and insert it into a Locks object at the
same time.

The ownership of the backing array for the slice of hashes passes to this
function, and so the caller must not read or write that backing array after
calling NewProviderLock.

Only lockable providers can be passed to this method. If you pass a
non-lockable provider address then this function will panic. Use
function ProviderIsLockable to determine whether a particular provider
should participate in the version locking mechanism.
// NewProviderLock creates a new ProviderLock object that isn ' t associated // with any Locks object . // // This is here primarily for testing . Most callers should use Locks . SetProvider // to construct a new provider lock and insert it into a Locks object at the // same time . // // The ownership of the backing array for the slice of hashes passes to this // function and so the caller must not read or write that backing array after // calling NewProviderLock . // // Only lockable providers can be passed to this method . If you pass a // non - lockable provider address then this function will panic . Use // function ProviderIsLockable to determine whether a particular provider // should participate in the version locking mechanism .
func NewProviderLock(addr addrs.Provider, version getproviders.Version, constraints getproviders.VersionConstraints, hashes []getproviders.Hash) *ProviderLock {
	if !ProviderIsLockable(addr) {
		panic(fmt.Sprintf("Locks.NewProviderLock with non-lockable provider %s", addr))
	}
	sort.Slice(hashes, func(i, j int) bool {
		return string(hashes[i]) < string(hashes[j])
	})
	dedupeHashes := hashes[:0]
	prevHash := getproviders.NilHash
	for _, hash := range hashes {
		if hash != prevHash {
			dedupeHashes = append(dedupeHashes, hash)
			prevHash = hash
		}
	}
	return &ProviderLock{
		addr:               addr,
		version:            version,
		versionConstraints: constraints,
		hashes:             dedupeHashes,
	}
}
func NewProviderLock ( addr addrs . Provider , version getproviders . Version , constraints getproviders . VersionConstraints , hashes [ ] getproviders . Hash ) * ProviderLock { if ! ProviderIsLockable ( addr ) { panic ( fmt . Sprintf ( " " , addr ) ) } sort . Slice ( hashes , func ( i , j int ) bool { return string ( hashes [ i ] ) < string ( hashes [ j ] ) } ) dedupeHashes := hashes [ : 0 ] prevHash := getproviders . NilHash for _ , hash := range hashes { if hash != prevHash { dedupeHashes = append ( dedupeHashes , hash ) prevHash = hash } } return & ProviderLock { addr : addr , version : version , versionConstraints : constraints , hashes : dedupeHashes , } }
NewProviderLock creates a new ProviderLock object that isn't associated
with any Locks object.
NewProviderLock creates a new ProviderLock object that isn ' t associated with any Locks object .
// Normalize the hashes into lexical order so that we can do straightforward // equality tests between different locks for the same provider. The // hashes are logically a set, so the given order is insignificant. // This is a slightly-tricky in-place deduping to avoid unnecessarily // allocating a new array in the common case where there are no duplicates: // we iterate over "hashes" at the same time as appending to another slice // with the same backing array, relying on the fact that deduping can only // _skip_ elements from the input, and will never generate additional ones // that would cause the writer to get ahead of the reader. This also // assumes that we already sorted the items, which means that any duplicates // will be consecutive in the sequence.