Skip to content

Commit

Permalink
Merge pull request #2111 from stevvooe/use-digest-package
Browse files Browse the repository at this point in the history
digest: use new go-digest package
  • Loading branch information
stevvooe authored Jan 7, 2017
2 parents 534b155 + 72150be commit 7dba427
Show file tree
Hide file tree
Showing 68 changed files with 116 additions and 378 deletions.
2 changes: 1 addition & 1 deletion blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

"github.com/docker/distribution/context"
"github.com/docker/distribution/digest"
"github.com/docker/distribution/reference"
"github.com/opencontainers/go-digest"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/digest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"log"
"os"

"github.com/docker/distribution/digest"
"github.com/docker/distribution/version"
"github.com/opencontainers/go-digest"
)

var (
Expand Down
100 changes: 0 additions & 100 deletions digest/algorithm_test.go

This file was deleted.

92 changes: 0 additions & 92 deletions digest/digest_test.go

This file was deleted.

66 changes: 0 additions & 66 deletions digest/verifiers_test.go

This file was deleted.

30 changes: 16 additions & 14 deletions digest/set.go → digestset/set.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package digest
package digestset

import (
"errors"
"sort"
"strings"
"sync"

digest "github.com/opencontainers/go-digest"
)

var (
Expand Down Expand Up @@ -44,7 +46,7 @@ func NewSet() *Set {
// values or short values. This function does not test equality,
// rather whether the second value could match against the first
// value.
func checkShortMatch(alg Algorithm, hex, shortAlg, shortHex string) bool {
func checkShortMatch(alg digest.Algorithm, hex, shortAlg, shortHex string) bool {
if len(hex) == len(shortHex) {
if hex != shortHex {
return false
Expand All @@ -64,19 +66,19 @@ func checkShortMatch(alg Algorithm, hex, shortAlg, shortHex string) bool {
// If no digests could be found ErrDigestNotFound will be returned
// with an empty digest value. If multiple matches are found
// ErrDigestAmbiguous will be returned with an empty digest value.
func (dst *Set) Lookup(d string) (Digest, error) {
func (dst *Set) Lookup(d string) (digest.Digest, error) {
dst.mutex.RLock()
defer dst.mutex.RUnlock()
if len(dst.entries) == 0 {
return "", ErrDigestNotFound
}
var (
searchFunc func(int) bool
alg Algorithm
alg digest.Algorithm
hex string
)
dgst, err := Parse(d)
if err == ErrDigestInvalidFormat {
dgst, err := digest.Parse(d)
if err == digest.ErrDigestInvalidFormat {
hex = d
searchFunc = func(i int) bool {
return dst.entries[i].val >= d
Expand Down Expand Up @@ -108,7 +110,7 @@ func (dst *Set) Lookup(d string) (Digest, error) {
// Add adds the given digest to the set. An error will be returned
// if the given digest is invalid. If the digest already exists in the
// set, this operation will be a no-op.
func (dst *Set) Add(d Digest) error {
func (dst *Set) Add(d digest.Digest) error {
if err := d.Validate(); err != nil {
return err
}
Expand Down Expand Up @@ -139,7 +141,7 @@ func (dst *Set) Add(d Digest) error {
// Remove removes the given digest from the set. An err will be
// returned if the given digest is invalid. If the digest does
// not exist in the set, this operation will be a no-op.
func (dst *Set) Remove(d Digest) error {
func (dst *Set) Remove(d digest.Digest) error {
if err := d.Validate(); err != nil {
return err
}
Expand Down Expand Up @@ -167,10 +169,10 @@ func (dst *Set) Remove(d Digest) error {
}

// All returns all the digests in the set
func (dst *Set) All() []Digest {
func (dst *Set) All() []digest.Digest {
dst.mutex.RLock()
defer dst.mutex.RUnlock()
retValues := make([]Digest, len(dst.entries))
retValues := make([]digest.Digest, len(dst.entries))
for i := range dst.entries {
retValues[i] = dst.entries[i].digest
}
Expand All @@ -183,10 +185,10 @@ func (dst *Set) All() []Digest {
// entire value of digest if uniqueness cannot be achieved without the
// full value. This function will attempt to make short codes as short
// as possible to be unique.
func ShortCodeTable(dst *Set, length int) map[Digest]string {
func ShortCodeTable(dst *Set, length int) map[digest.Digest]string {
dst.mutex.RLock()
defer dst.mutex.RUnlock()
m := make(map[Digest]string, len(dst.entries))
m := make(map[digest.Digest]string, len(dst.entries))
l := length
resetIdx := 0
for i := 0; i < len(dst.entries); i++ {
Expand Down Expand Up @@ -222,9 +224,9 @@ func ShortCodeTable(dst *Set, length int) map[Digest]string {
}

type digestEntry struct {
alg Algorithm
alg digest.Algorithm
val string
digest Digest
digest digest.Digest
}

type digestEntries []*digestEntry
Expand Down
Loading

0 comments on commit 7dba427

Please sign in to comment.