Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Jul 6, 2017
1 parent 5bfa12e commit 6f32508
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 82 deletions.
2 changes: 1 addition & 1 deletion cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dep/ensure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/dep/glide_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions cmd/dep/godep_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 7 additions & 67 deletions internal/gps/solve_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\.\*]*)`)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/gps/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6f32508

Please sign in to comment.