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

Consolidate ProjectIndentifier sorts; drop build support for go1.7 #714

Merged
merged 2 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- codeclimate-test-reporter < coverage.txt
# YAML alias, for settings shared across the simpler builds
- &simple-test
go: 1.7.x
go: 1.9.x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it needs to be just 1.9

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was holding out for them to update and it looks like they did at some point today. Travis is now recognizing 1.9.x and passing only 1.9 to gimme. Strange that they don't have a general rule for picking up 1.Y.X for any Y though.

stage: test
install: skip
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Dep

`dep` is a prototype dependency management tool for Go. It requires Go 1.7 or newer to compile.
`dep` is a prototype dependency management tool for Go. It requires Go 1.8 or newer to compile.

`dep` is the official _experiment_, but not yet the official tool. Check out the [Roadmap](https://github.com/golang/dep/wiki/Roadmap) for more on what this means!

Expand Down
4 changes: 3 additions & 1 deletion cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
// deterministically ordered. (This may be superfluous if the lock is always
// written in alpha order, but it doesn't hurt to double down.)
slp := p.Lock.Projects()
sort.Sort(dep.SortedLockedProjects(slp))
sort.Slice(slp, func(i, j int) bool {
return slp[i].Ident().Less(slp[j].Ident())
})

if bytes.Equal(s.HashInputs(), p.Lock.SolveMeta.InputsDigest) {
// If these are equal, we're guaranteed that the lock is a transitively
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func RenameWithFallback(src, dst string) error {
return errors.Wrapf(err, "cannot stat %s", src)
}

err = rename(src, dst)
err = os.Rename(src, dst)
if err == nil {
return nil
}
Expand Down
5 changes: 0 additions & 5 deletions internal/fs/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

// +build !windows
// +build go1.8

package fs

Expand All @@ -14,10 +13,6 @@ import (
"github.com/pkg/errors"
)

func rename(src, dst string) error {
return os.Rename(src, dst)
}

// renameFallback attempts to determine the appropriate fallback to failed rename
// operation depending on the resulting error.
func renameFallback(err error, src, dst string) error {
Expand Down
50 changes: 0 additions & 50 deletions internal/fs/rename_go17.go

This file was deleted.

4 changes: 0 additions & 4 deletions internal/fs/rename_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
"github.com/pkg/errors"
)

func rename(src, dst string) error {
return os.Rename(src, dst)
}

// renameFallback attempts to determine the appropriate fallback to failed rename
// operation depending on the resulting error.
func renameFallback(err error, src, dst string) error {
Expand Down
20 changes: 6 additions & 14 deletions internal/gps/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ func (m ProjectConstraints) asSortedSlice() []ProjectConstraint {
k++
}

sort.Stable(sortedConstraints(pcs))
sort.SliceStable(pcs, func(i, j int) bool {
return pcs[i].Ident.Less(pcs[j].Ident)
})
return pcs
}

Expand All @@ -348,7 +350,9 @@ func (m ProjectConstraints) overrideAll(pcm ProjectConstraints) (out []workingCo
k++
}

sort.Stable(sortedWC(out))
sort.SliceStable(out, func(i, j int) bool {
return out[i].Ident.Less(out[j].Ident)
})
return
}

Expand Down Expand Up @@ -389,15 +393,3 @@ func (m ProjectConstraints) override(pr ProjectRoot, pp ProjectProperties) worki

return wc
}

type sortedConstraints []ProjectConstraint

func (s sortedConstraints) Len() int { return len(s) }
func (s sortedConstraints) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s sortedConstraints) Less(i, j int) bool { return s[i].Ident.less(s[j].Ident) }

type sortedWC []workingConstraint

func (s sortedWC) Len() int { return len(s) }
func (s sortedWC) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s sortedWC) Less(i, j int) bool { return s[i].Ident.less(s[j].Ident) }
4 changes: 2 additions & 2 deletions internal/gps/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ type ProjectIdentifier struct {
Source string
}

func (i ProjectIdentifier) less(j ProjectIdentifier) bool {
// Less compares by ProjectRoot then normalized Source.
func (i ProjectIdentifier) Less(j ProjectIdentifier) bool {
if i.ProjectRoot < j.ProjectRoot {
return true
}
if j.ProjectRoot < i.ProjectRoot {
return false
}

return i.normalizedSource() < j.normalizedSource()
}

Expand Down
51 changes: 17 additions & 34 deletions internal/gps/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,8 @@ func LocksAreEq(l1, l2 Lock, checkHash bool) bool {
return false
}

// Check if the slices are sorted already. If they are, we can compare
// without copying. Otherwise, we have to copy to avoid altering the
// original input.
sp1, sp2 := lpsorter(p1), lpsorter(p2)
if len(p1) > 1 && !sort.IsSorted(sp1) {
p1 = make([]LockedProject, len(p1))
copy(p1, l1.Projects())
sort.Sort(lpsorter(p1))
}
if len(p2) > 1 && !sort.IsSorted(sp2) {
p2 = make([]LockedProject, len(p2))
copy(p2, l2.Projects())
sort.Sort(lpsorter(p2))
}
p1 = sortedLockedProjects(p1)
p2 = sortedLockedProjects(p2)

for k, lp := range p1 {
if !lp.Eq(p2[k]) {
Expand All @@ -62,6 +50,21 @@ func LocksAreEq(l1, l2 Lock, checkHash bool) bool {
return true
}

// sortedLockedProjects returns a sorted copy of lps, or itself if already sorted.
func sortedLockedProjects(lps []LockedProject) []LockedProject {
if len(lps) <= 1 || sort.SliceIsSorted(lps, func(i, j int) bool {
return lps[i].Ident().Less(lps[j].Ident())
}) {
return lps
}
cp := make([]LockedProject, len(lps))
copy(cp, lps)
sort.Slice(cp, func(i, j int) bool {
return cp[i].Ident().Less(cp[j].Ident())
})
return cp
}

// LockedProject is a single project entry from a lock file. It expresses the
// project's name, one or both of version and underlying revision, the network
// URI for accessing it, the path at which it should be placed within a vendor
Expand Down Expand Up @@ -230,23 +233,3 @@ func prepLock(l Lock) safeLock {

return rl
}

// SortLockedProjects sorts a slice of LockedProject in alphabetical order by
// ProjectIdentifier.
func SortLockedProjects(lps []LockedProject) {
sort.Stable(lpsorter(lps))
}

type lpsorter []LockedProject

func (lps lpsorter) Swap(i, j int) {
lps[i], lps[j] = lps[j], lps[i]
}

func (lps lpsorter) Len() int {
return len(lps)
}

func (lps lpsorter) Less(i, j int) bool {
return lps[i].Ident().less(lps[j].Ident())
}
5 changes: 4 additions & 1 deletion internal/gps/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gps

import (
"reflect"
"sort"
"testing"
)

Expand All @@ -20,7 +21,9 @@ func TestLockedProjectSorting(t *testing.T) {
lps2 := make([]LockedProject, len(lps))
copy(lps2, lps)

SortLockedProjects(lps2)
sort.SliceStable(lps2, func(i, j int) bool {
return lps2[i].Ident().Less(lps2[j].Ident())
})

// only the two should have switched positions
lps[0], lps[2] = lps[2], lps[0]
Expand Down
16 changes: 2 additions & 14 deletions internal/gps/lockdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,8 @@ func DiffLocks(l1 Lock, l2 Lock) *LockDiff {

p1, p2 := l1.Projects(), l2.Projects()

// Check if the slices are sorted already. If they are, we can compare
// without copying. Otherwise, we have to copy to avoid altering the
// original input.
sp1, sp2 := lpsorter(p1), lpsorter(p2)
if len(p1) > 1 && !sort.IsSorted(sp1) {
p1 = make([]LockedProject, len(p1))
copy(p1, l1.Projects())
sort.Sort(lpsorter(p1))
}
if len(p2) > 1 && !sort.IsSorted(sp2) {
p2 = make([]LockedProject, len(p2))
copy(p2, l2.Projects())
sort.Sort(lpsorter(p2))
}
p1 = sortedLockedProjects(p1)
p2 = sortedLockedProjects(p2)

diff := LockDiff{}

Expand Down
10 changes: 5 additions & 5 deletions internal/gps/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func mkNaiveSM(t *testing.T) (*SourceMgr, func()) {

return sm, func() {
sm.Release()
err := removeAll(cpath)
err := os.RemoveAll(cpath)
if err != nil {
t.Errorf("removeAll failed: %s", err)
}
Expand All @@ -65,7 +65,7 @@ func remakeNaiveSM(osm *SourceMgr, t *testing.T) (*SourceMgr, func()) {

return sm, func() {
sm.Release()
err := removeAll(cpath)
err := os.RemoveAll(cpath)
if err != nil {
t.Errorf("removeAll failed: %s", err)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestSourceManagerInit(t *testing.T) {
}

sm.Release()
err = removeAll(cpath)
err = os.RemoveAll(cpath)
if err != nil {
t.Errorf("removeAll failed: %s", err)
}
Expand All @@ -111,7 +111,7 @@ func TestSourceManagerInit(t *testing.T) {
}

sm.Release()
err = removeAll(cpath)
err = os.RemoveAll(cpath)
if err != nil {
t.Errorf("removeAll failed: %s", err)
}
Expand All @@ -135,7 +135,7 @@ func TestSourceInit(t *testing.T) {

defer func() {
sm.Release()
err := removeAll(cpath)
err := os.RemoveAll(cpath)
if err != nil {
t.Errorf("removeAll failed: %s", err)
}
Expand Down
48 changes: 0 additions & 48 deletions internal/gps/remove_go16.go

This file was deleted.

15 changes: 0 additions & 15 deletions internal/gps/remove_go17.go

This file was deleted.

Loading