From 6f32508ff2075cd3f868eff1581307d933995112 Mon Sep 17 00:00:00 2001 From: marwan-at-work Date: Thu, 6 Jul 2017 11:25:20 -0400 Subject: [PATCH] pr fixes --- cmd/dep/ensure.go | 2 +- cmd/dep/ensure_test.go | 4 +- cmd/dep/glide_importer.go | 8 ++-- cmd/dep/godep_importer.go | 8 ++-- internal/gps/solve_basic_test.go | 74 +++----------------------------- internal/gps/source_manager.go | 8 ++-- 6 files changed, 22 insertions(+), 82 deletions(-) diff --git a/cmd/dep/ensure.go b/cmd/dep/ensure.go index 371e8165aa..30fb177057 100644 --- a/cmd/dep/ensure.go +++ b/cmd/dep/ensure.go @@ -296,7 +296,7 @@ func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstrai } pi := gps.ProjectIdentifier{ProjectRoot: pr, Source: source} - c, err := sm.DeduceConstraint(versionStr, pi) + c, err := sm.InferConstraint(versionStr, pi) if err != nil { return emptyPC, err } diff --git a/cmd/dep/ensure_test.go b/cmd/dep/ensure_test.go index 0bff840c54..f30c7d36fa 100644 --- a/cmd/dep/ensure_test.go +++ b/cmd/dep/ensure_test.go @@ -38,7 +38,7 @@ func TestDeduceConstraint(t *testing.T) { pi := gps.ProjectIdentifier{ProjectRoot: "github.com/sdboyer/deptest"} for str, want := range constraints { - got, err := sm.DeduceConstraint(str, pi) + got, err := sm.InferConstraint(str, pi) h.Must(err) wantT := reflect.TypeOf(want) @@ -68,7 +68,7 @@ func TestDeduceConstraint_InvalidInput(t *testing.T) { pi := gps.ProjectIdentifier{ProjectRoot: "github.com/sdboyer/deptest"} for _, str := range constraints { - _, err := sm.DeduceConstraint(str, pi) + _, err := sm.InferConstraint(str, pi) if err == nil { t.Errorf("expected %s to produce an error", str) } diff --git a/cmd/dep/glide_importer.go b/cmd/dep/glide_importer.go index 0150791920..43c0efca0c 100644 --- a/cmd/dep/glide_importer.go +++ b/cmd/dep/glide_importer.go @@ -206,10 +206,10 @@ func (g *glideImporter) buildProjectConstraint(pkg glidePackage) (pc gps.Project } pc.Ident = gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(pkg.Name), Source: pkg.Repository} - pc.Constraint, err = g.sm.DeduceConstraint(pkg.Reference, pc.Ident) - if err != nil { - return - } + pc.Constraint, err = g.sm.InferConstraint(pkg.Reference, pc.Ident) + if err != nil { + return + } f := fb.NewConstraintFeedback(pc, fb.DepTypeImported) f.LogFeedback(g.logger) diff --git a/cmd/dep/godep_importer.go b/cmd/dep/godep_importer.go index 3094d53c84..494891f14b 100644 --- a/cmd/dep/godep_importer.go +++ b/cmd/dep/godep_importer.go @@ -158,10 +158,10 @@ func (g *godepImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e // create a project constraint func (g *godepImporter) buildProjectConstraint(pkg godepPackage) (pc gps.ProjectConstraint, err error) { pc.Ident = gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(pkg.ImportPath)} - pc.Constraint, err = g.sm.DeduceConstraint(pkg.Comment, pc.Ident) - if err != nil { - return - } + pc.Constraint, err = g.sm.InferConstraint(pkg.Comment, pc.Ident) + if err != nil { + return + } f := fb.NewConstraintFeedback(pc, fb.DepTypeImported) f.LogFeedback(g.logger) diff --git a/internal/gps/solve_basic_test.go b/internal/gps/solve_basic_test.go index 79e90267a5..6c47815008 100644 --- a/internal/gps/solve_basic_test.go +++ b/internal/gps/solve_basic_test.go @@ -5,15 +5,12 @@ package gps import ( - "encoding/hex" "fmt" "regexp" - "strconv" "strings" "github.com/Masterminds/semver" "github.com/golang/dep/internal/gps/pkgtree" - "github.com/pkg/errors" ) var regfrom = regexp.MustCompile(`^(\w*) from (\w*) ([0-9\.\*]*)`) @@ -1497,70 +1494,13 @@ func (sm *depspecSourceManager) ignore() map[string]bool { return sm.ig } -// DeduceConstraint tries to puzzle out what kind of version is given in a string - -// semver, a revision, or as a fallback, a plain tag -func (sm *depspecSourceManager) DeduceConstraint(s string, pi ProjectIdentifier) (Constraint, error) { - if s == "" { - // Find the default branch - versions, err := sm.ListVersions(pi) - if err != nil { - return nil, errors.Wrapf(err, "list versions for %s(%s)", pi.ProjectRoot, pi.Source) // means repo does not exist - } - - SortPairedForUpgrade(versions) - for _, v := range versions { - if v.Type() == IsBranch { - return v.Unpair(), nil - } - } - } - - // always semver if we can - c, err := NewSemverConstraintIC(s) - if err == nil { - return c, nil - } - - slen := len(s) - if slen == 40 { - if _, err = hex.DecodeString(s); err == nil { - // Whether or not it's intended to be a SHA1 digest, this is a - // valid byte sequence for that, so go with Revision. This - // covers git and hg - return Revision(s), nil - } - } - // Next, try for bzr, which has a three-component GUID separated by - // dashes. There should be two, but the email part could contain - // internal dashes - if strings.Count(s, "-") >= 2 { - // Work from the back to avoid potential confusion from the email - i3 := strings.LastIndex(s, "-") - // Skip if - is last char, otherwise this would panic on bounds err - if slen == i3+1 { - return NewVersion(s), nil - } - - i2 := strings.LastIndex(s[:i3], "-") - if _, err = strconv.ParseUint(s[i2+1:i3], 10, 64); err == nil { - // Getting this far means it'd pretty much be nuts if it's not a - // bzr rev, so don't bother parsing the email. - return Revision(s), nil - } - } - - // call out to network and get the package's versions - versions, err := sm.ListVersions(pi) - if err != nil { - return nil, errors.Wrapf(err, "list versions for %s(%s)", pi.ProjectRoot, pi.Source) // means repo does not exist - } - - for _, version := range versions { - if s == version.String() { - return version.Unpair(), nil - } - } - return nil, errors.Errorf("%s is not a valid version for the package %s(%s)", s, pi.ProjectRoot, pi.Source) +// InferConstraint tries to puzzle out what kind of version is given in a string - +// semver, a revision, or as a fallback, a plain tag. This current implementation +// is a panic because there's no current circumstance under which the depspecSourceManager +// is useful outside of the gps solving tests, and it shouldn't be used anywhere else without a conscious and intentional +// expansion of its semantics. +func (sm *depspecSourceManager) InferConstraint(s string, pi ProjectIdentifier) (Constraint, error) { + panic("depsecSourceManager is only for gps solving tests") } type depspecBridge struct { diff --git a/internal/gps/source_manager.go b/internal/gps/source_manager.go index af7bdb10a5..9d7b8ff21f 100644 --- a/internal/gps/source_manager.go +++ b/internal/gps/source_manager.go @@ -76,9 +76,9 @@ type SourceManager interface { // immediately result in errors. Release() - // DeduceConstraint tries to puzzle out what kind of version is given in a string - + // InferConstraint tries to puzzle out what kind of version is given in a string - // semver, a revision, or as a fallback, a plain tag - DeduceConstraint(s string, pi ProjectIdentifier) (Constraint, error) + InferConstraint(s string, pi ProjectIdentifier) (Constraint, error) } // A ProjectAnalyzer is responsible for analyzing a given path for Manifest and @@ -462,9 +462,9 @@ func (sm *SourceMgr) DeduceProjectRoot(ip string) (ProjectRoot, error) { return ProjectRoot(pd.root), err } -// DeduceConstraint tries to puzzle out what kind of version is given in a string - +// InferConstraint tries to puzzle out what kind of version is given in a string - // semver, a revision, or as a fallback, a plain tag -func (sm *SourceMgr) DeduceConstraint(s string, pi ProjectIdentifier) (Constraint, error) { +func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint, error) { if s == "" { // Find the default branch versions, err := sm.ListVersions(pi)