Merge pull request #490 from Masterminds/fix-goreportcard

Cleanup from go report card
diff --git a/action/install.go b/action/install.go
index 3deb9d2..bf17caa 100644
--- a/action/install.go
+++ b/action/install.go
@@ -1,7 +1,6 @@
 package action
 
 import (
-	"io/ioutil"
 	"path/filepath"
 
 	"github.com/Masterminds/glide/cache"
@@ -31,10 +30,17 @@
 		return
 	}
 	// Load lockfile
-	lock, err := LoadLockfile(base, conf)
+	lock, err := cfg.ReadLockFile(filepath.Join(base, gpath.LockFile))
 	if err != nil {
 		msg.Die("Could not load lockfile.")
 	}
+	// Verify lockfile hasn't changed
+	hash, err := conf.Hash()
+	if err != nil {
+		msg.Die("Could not load lockfile.")
+	} else if hash != lock.Hash {
+		msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
+	}
 
 	// Delete unused packages
 	if installer.DeleteUnused {
@@ -77,28 +83,3 @@
 		}
 	}
 }
-
-// LoadLockfile loads the contents of a glide.lock file.
-//
-// TODO: This should go in another package.
-func LoadLockfile(base string, conf *cfg.Config) (*cfg.Lockfile, error) {
-	yml, err := ioutil.ReadFile(filepath.Join(base, gpath.LockFile))
-	if err != nil {
-		return nil, err
-	}
-	lock, err := cfg.LockfileFromYaml(yml)
-	if err != nil {
-		return nil, err
-	}
-
-	hash, err := conf.Hash()
-	if err != nil {
-		return nil, err
-	}
-
-	if hash != lock.Hash {
-		msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
-	}
-
-	return lock, nil
-}
diff --git a/cfg/config.go b/cfg/config.go
index cdfd943..4b4e799 100644
--- a/cfg/config.go
+++ b/cfg/config.go
@@ -390,6 +390,19 @@
 	Os          []string `yaml:"os,omitempty"`
 }
 
+// DependencyFromLock converts a Lock to a Dependency
+func DependencyFromLock(lock *Lock) *Dependency {
+	return &Dependency{
+		Name:        lock.Name,
+		Reference:   lock.Version,
+		Repository:  lock.Repository,
+		VcsType:     lock.VcsType,
+		Subpackages: lock.Subpackages,
+		Arch:        lock.Arch,
+		Os:          lock.Os,
+	}
+}
+
 // UnmarshalYAML is a hook for gopkg.in/yaml.v2 in the unmarshaling process
 func (d *Dependency) UnmarshalYAML(unmarshal func(interface{}) error) error {
 	newDep := &dep{}
diff --git a/cfg/lock.go b/cfg/lock.go
index 2b2c4c8..215483c 100644
--- a/cfg/lock.go
+++ b/cfg/lock.go
@@ -72,6 +72,19 @@
 	return sha256.Sum256(yml), nil
 }
 
+// ReadLockFile loads the contents of a glide.lock file.
+func ReadLockFile(lockpath string) (*Lockfile, error) {
+	yml, err := ioutil.ReadFile(lockpath)
+	if err != nil {
+		return nil, err
+	}
+	lock, err := LockfileFromYaml(yml)
+	if err != nil {
+		return nil, err
+	}
+	return lock, nil
+}
+
 // Locks is a slice of locked dependencies.
 type Locks []*Lock
 
@@ -130,6 +143,19 @@
 	}
 }
 
+// LockFromDependency converts a Dependency to a Lock
+func LockFromDependency(dep *Dependency) *Lock {
+	return &Lock{
+		Name:        dep.Name,
+		Version:     dep.Pin,
+		Repository:  dep.Repository,
+		VcsType:     dep.VcsType,
+		Subpackages: dep.Subpackages,
+		Arch:        dep.Arch,
+		Os:          dep.Os,
+	}
+}
+
 // NewLockfile is used to create an instance of Lockfile.
 func NewLockfile(ds, tds Dependencies, hash string) *Lockfile {
 	lf := &Lockfile{
@@ -140,29 +166,13 @@
 	}
 
 	for i := 0; i < len(ds); i++ {
-		lf.Imports[i] = &Lock{
-			Name:        ds[i].Name,
-			Version:     ds[i].Pin,
-			Repository:  ds[i].Repository,
-			VcsType:     ds[i].VcsType,
-			Subpackages: ds[i].Subpackages,
-			Arch:        ds[i].Arch,
-			Os:          ds[i].Os,
-		}
+		lf.Imports[i] = LockFromDependency(ds[i])
 	}
 
 	sort.Sort(lf.Imports)
 
 	for i := 0; i < len(tds); i++ {
-		lf.DevImports[i] = &Lock{
-			Name:        tds[i].Name,
-			Version:     tds[i].Pin,
-			Repository:  tds[i].Repository,
-			VcsType:     tds[i].VcsType,
-			Subpackages: tds[i].Subpackages,
-			Arch:        tds[i].Arch,
-			Os:          tds[i].Os,
-		}
+		lf.DevImports[i] = LockFromDependency(tds[i])
 	}
 
 	sort.Sort(lf.DevImports)
@@ -180,15 +190,8 @@
 
 	i := 0
 	for name, dep := range ds {
-		lf.Imports[i] = &Lock{
-			Name:        name,
-			Version:     dep.Pin,
-			Repository:  dep.Repository,
-			VcsType:     dep.VcsType,
-			Subpackages: dep.Subpackages,
-			Arch:        dep.Arch,
-			Os:          dep.Os,
-		}
+		lf.Imports[i] = LockFromDependency(dep)
+		lf.Imports[i].Name = name
 		i++
 	}
 
diff --git a/docs/versions.md b/docs/versions.md
index a323fb2..047a5ce 100644
--- a/docs/versions.md
+++ b/docs/versions.md
@@ -27,7 +27,7 @@
 
 * `1.2.x` is equivalent to `>= 1.2.0, < 1.3.0`
 * `>= 1.2.x` is equivalent to `>= 1.2.0`
-* `<= 2.x` is equivalent to `<= 3`
+* `<= 2.x` is equivalent to `< 3`
 * `*` is equivalent to `>= 0.0.0`
 
 ## Tilde Range Comparisons (Patch)
diff --git a/repo/installer.go b/repo/installer.go
index b8ebcfe..fee26c4 100644
--- a/repo/installer.go
+++ b/repo/installer.go
@@ -94,28 +94,12 @@
 
 	newConf.Imports = make(cfg.Dependencies, len(lock.Imports))
 	for k, v := range lock.Imports {
-		newConf.Imports[k] = &cfg.Dependency{
-			Name:        v.Name,
-			Reference:   v.Version,
-			Repository:  v.Repository,
-			VcsType:     v.VcsType,
-			Subpackages: v.Subpackages,
-			Arch:        v.Arch,
-			Os:          v.Os,
-		}
+		newConf.Imports[k] = cfg.DependencyFromLock(v)
 	}
 
 	newConf.DevImports = make(cfg.Dependencies, len(lock.DevImports))
 	for k, v := range lock.DevImports {
-		newConf.DevImports[k] = &cfg.Dependency{
-			Name:        v.Name,
-			Reference:   v.Version,
-			Repository:  v.Repository,
-			VcsType:     v.VcsType,
-			Subpackages: v.Subpackages,
-			Arch:        v.Arch,
-			Os:          v.Os,
-		}
+		newConf.DevImports[k] = cfg.DependencyFromLock(v)
 	}
 
 	newConf.DeDupe()