Trim out all the crufty fields from cfg structs
diff --git a/cfg/config.go b/cfg/config.go
index d600ac3..3f8381d 100644
--- a/cfg/config.go
+++ b/cfg/config.go
@@ -5,7 +5,6 @@
"encoding/hex"
"fmt"
"io/ioutil"
- "reflect"
"sort"
"strconv"
"strings"
@@ -68,7 +67,7 @@
Ignore []string `yaml:"ignore,omitempty"`
Imports Dependencies `yaml:"dependencies,omitempty"`
DevImports Dependencies `yaml:"testDependencies,omitempty"`
- // used to guarantee that this wil fail on unmarshaling legacy yamls
+ // these fields guarantee that this struct fails to unmarshal legacy yamls
Compat int `yaml:"import,omitempty"`
Compat2 int `yaml:"testImport,omitempty"`
}
@@ -163,16 +162,16 @@
// DependencyConstraints lists all the non-test dependency constraints
// described in a glide manifest in a way gps will understand.
func (c *Config) DependencyConstraints() []gps.ProjectConstraint {
- return depsToVSolver(c.Imports)
+ return gpsifyDeps(c.Imports)
}
// TestDependencyConstraints lists all the test dependency constraints described
// in a glide manifest in a way gps will understand.
func (c *Config) TestDependencyConstraints() []gps.ProjectConstraint {
- return depsToVSolver(c.DevImports)
+ return gpsifyDeps(c.DevImports)
}
-func depsToVSolver(deps Dependencies) []gps.ProjectConstraint {
+func gpsifyDeps(deps Dependencies) []gps.ProjectConstraint {
cp := make([]gps.ProjectConstraint, len(deps))
for k, d := range deps {
cp[k] = gps.ProjectConstraint{
@@ -395,9 +394,6 @@
if dep.Repository != v.Repository {
return d, fmt.Errorf("Import %s repeated with different Repository details", dep.Name)
}
- if !reflect.DeepEqual(dep.Os, v.Os) || !reflect.DeepEqual(dep.Arch, v.Arch) {
- return d, fmt.Errorf("Import %s repeated with different OS or Architecture filtering", dep.Name)
- }
}
}
@@ -410,18 +406,14 @@
VcsType string // TODO remove
Constraint gps.Constraint
Repository string
- Arch []string
- Os []string
}
// A transitive representation of a dependency for yaml import/export.
type dep struct {
- Name string `yaml:"package"`
- Reference string `yaml:"version,omitempty"` // TODO rename
- Branch string `yaml:"branch,omitempty"`
- Repository string `yaml:"repo,omitempty"`
- Arch []string `yaml:"arch,omitempty"`
- Os []string `yaml:"os,omitempty"`
+ Name string `yaml:"package"`
+ Reference string `yaml:"version,omitempty"` // TODO rename
+ Branch string `yaml:"branch,omitempty"`
+ Repository string `yaml:"repo,omitempty"`
}
// DependencyFromLock converts a Lock to a Dependency
@@ -453,8 +445,6 @@
d.Name = newDep.Name
d.Repository = newDep.Repository
- d.Arch = newDep.Arch
- d.Os = newDep.Os
if newDep.Reference != "" {
r := newDep.Reference
@@ -486,9 +476,9 @@
return nil
}
-// deduceConstraint tries to puzzle out what kind of version is given in a string -
+// 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 deduceConstraint(s string) gps.Constraint {
+func DeduceConstraint(s string) gps.Constraint {
// always semver if we can
c, err := gps.NewSemverConstraint(s)
if err == nil {
@@ -536,8 +526,6 @@
newDep := &dep{
Name: d.Name,
Repository: d.Repository,
- Arch: d.Arch,
- Os: d.Os,
}
// Pull out the correct type of constraint
@@ -603,12 +591,6 @@
return &d2
}
-// HasSubpackage returns if the subpackage is present on the dependency
-// TODO remove
-func (d *Dependency) HasSubpackage(sub string) bool {
- return false
-}
-
// Owners is a list of owners for a project.
type Owners []*Owner
diff --git a/cfg/config_test.go b/cfg/config_test.go
index bbdfc48..09be399 100644
--- a/cfg/config_test.go
+++ b/cfg/config_test.go
@@ -359,21 +359,21 @@
func TestDeduceConstraint(t *testing.T) {
// First, valid semver
- c := deduceConstraint("v1.0.0")
+ c := DeduceConstraint("v1.0.0")
if c.(gps.Version).Type() != "semver" {
t.Errorf("Got unexpected version type when passing valid semver string: %T %s", c, c)
}
// Now, 20 hex-encoded bytes (which should be assumed to be a SHA1 digest)
revin := "a9949121a2e2192ca92fa6dddfeaaa4a4412d955"
- c = deduceConstraint(revin)
+ c = DeduceConstraint(revin)
if c != gps.Revision(revin) {
t.Errorf("Got unexpected version type/val when passing hex-encoded SHA1 digest: %T %s", c, c)
}
// Now, the weird bzr guid
bzrguid := "john@smith.org-20051026185030-93c7cad63ee570df"
- c = deduceConstraint(bzrguid)
+ c = DeduceConstraint(bzrguid)
if c != gps.Revision(bzrguid) {
t.Errorf("Expected revision with valid bzr guid, got: %T %s", c, c)
}
@@ -381,21 +381,21 @@
// Check fails if the bzr rev is malformed or weirdly formed
//
// chopping off a char should make the hex decode check fail
- c = deduceConstraint(bzrguid[:len(bzrguid)-1])
+ c = DeduceConstraint(bzrguid[:len(bzrguid)-1])
if c != gps.NewVersion(bzrguid[:len(bzrguid)-1]) {
t.Errorf("Expected plain version when bzr guid has truncated tail hex bits: %T %s", c, c)
}
// Extra dash in email doesn't mess us up
bzrguid2 := "john-smith@smith.org-20051026185030-93c7cad63ee570df"
- c = deduceConstraint(bzrguid2)
+ c = DeduceConstraint(bzrguid2)
if c != gps.Revision(bzrguid2) {
t.Errorf("Expected revision when passing bzr guid has extra dash in email, got: %T %s", c, c)
}
// Non-numeric char in middle section bites it
bzrguid3 := "john-smith@smith.org-2005102a6185030-93c7cad63ee570df"
- c = deduceConstraint(bzrguid3)
+ c = DeduceConstraint(bzrguid3)
if c != gps.NewVersion(bzrguid3) {
t.Errorf("Expected plain version when bzr guid has invalid second section, got: %T %s", c, c)
}
diff --git a/cfg/legacy.go b/cfg/legacy.go
index 3c78703..3364f9d 100644
--- a/cfg/legacy.go
+++ b/cfg/legacy.go
@@ -160,6 +160,9 @@
Exclude []string `yaml:"excludeDirs,omitempty"`
Imports lDependencies1 `yaml:"import"`
DevImports lDependencies1 `yaml:"testImport,omitempty"`
+ // these fields guarantee that this struct fails to unmarshal the new yamls
+ Compat int `yaml:"dependencies,omitempty"`
+ Compat2 int `yaml:"testDependencies,omitempty"`
}
type lDependencies1 []*lDependency1
@@ -183,7 +186,7 @@
Repository: d.Repository,
}
- d2.Constraint = deduceConstraint(d.Reference)
+ d2.Constraint = DeduceConstraint(d.Reference)
// TODO(sdboyer) if the above result is a plain version, the old
// semantics are ambiguous wrt if the user wants a branch or tag. Check
// the version list (via source manager) to convert most sanely?
diff --git a/cfg/lock.go b/cfg/lock.go
index 9bb23b4..fdf29a0 100644
--- a/cfg/lock.go
+++ b/cfg/lock.go
@@ -9,7 +9,6 @@
"strings"
"time"
- "github.com/Masterminds/semver"
"github.com/sdboyer/gps"
"gopkg.in/yaml.v2"
@@ -20,7 +19,7 @@
Hash string `yaml:"hash"`
Updated time.Time `yaml:"updated"`
Imports Locks `yaml:"imports"`
- DevImports Locks `yaml:"testImports"`
+ DevImports Locks `yaml:"testImports"` // TODO remove and fold in as prop
}
// LockfileFromSolverLock transforms a gps.Lock into a glide *Lockfile.
@@ -46,9 +45,16 @@
}
v := p.Version()
- if pv, ok := v.(gps.PairedVersion); ok {
- l.Version = pv.Underlying().String()
- } else {
+ // There's (currently) no way gps can emit a non-paired version in a
+ // solution, so this unchecked type assertion should be safe.
+ //
+ // TODO might still be better to check and return out with an err if
+ // not, though
+ l.Revision = v.(gps.PairedVersion).Underlying().String()
+ switch v.Type() {
+ case "branch":
+ l.Branch = v.String()
+ case "semver", "version":
l.Version = v.String()
}
@@ -130,21 +136,15 @@
lp := make([]gps.LockedProject, len(all))
for k, l := range all {
- // TODO guess the version type. ugh
- var v gps.Version
+ r := gps.Revision(l.Revision)
- // semver first
- _, err := semver.NewVersion(l.Version)
- if err == nil {
- v = gps.NewVersion(l.Version)
+ var v gps.Version
+ if l.Version != "" {
+ v = gps.NewVersion(l.Version).Is(r)
+ } else if l.Branch != "" {
+ v = gps.NewBranch(l.Branch).Is(r)
} else {
- // Crappy heuristic to cover hg and git, but not bzr. Or (lol) svn
- if len(l.Version) == 40 {
- v = gps.Revision(l.Version)
- } else {
- // Otherwise, assume it's a branch
- v = gps.NewBranch(l.Version)
- }
+ v = r
}
lp[k] = gps.NewLockedProject(gps.ProjectRoot(l.Name), v, l.Repository, nil)
@@ -166,6 +166,7 @@
// Fingerprint returns a hash of the contents minus the date. This allows for
// two lockfiles to be compared irrespective of their updated times.
+// TODO remove, or seriously re-adapt
func (lf *Lockfile) Fingerprint() ([32]byte, error) {
c := lf.Clone()
c.Updated = time.Time{} // Set the time to be the nil equivalent
@@ -243,6 +244,7 @@
}
// LockFromDependency converts a Dependency to a Lock
+// TODO remove
func LockFromDependency(dep *Dependency) *Lock {
l := &Lock{
Name: dep.Name,
@@ -253,6 +255,7 @@
}
// NewLockfile is used to create an instance of Lockfile.
+// TODO remove
func NewLockfile(ds, tds Dependencies, hash string) (*Lockfile, error) {
lf := &Lockfile{
Hash: hash,
@@ -290,6 +293,7 @@
}
// LockfileFromMap takes a map of dependencies and generates a lock Lockfile instance.
+// TODO remove
func LockfileFromMap(ds map[string]*Dependency, hash string) *Lockfile {
lf := &Lockfile{
Hash: hash,