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

Commit

Permalink
Fall back to 'sort.Slice' on Go 1.7 where 'sort.SliceStable' does not…
Browse files Browse the repository at this point in the history
… exist
  • Loading branch information
HaraldNordgren committed Jul 28, 2018
1 parent 224a564 commit 1baf6ee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions gps/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package gps

import (
"fmt"
"sort"

"github.com/Masterminds/semver"
"github.com/golang/dep/gps/internal/pb"
Expand Down Expand Up @@ -375,7 +374,7 @@ func (m ProjectConstraints) overrideAll(pcm ProjectConstraints) (out []workingCo
k++
}

sort.SliceStable(out, func(i, j int) bool {
sortSlice(out, func(i, j int) bool {
return out[i].Ident.Less(out[j].Ident)
})
return
Expand Down
2 changes: 1 addition & 1 deletion gps/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestLockedProjectSorting(t *testing.T) {
lps2 := make([]LockedProject, len(lps))
copy(lps2, lps)

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

Expand Down
9 changes: 9 additions & 0 deletions gps/sort_go_1_8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build go1.8

package gps

import "sort"

func sortSlice(slice interface{}, less func(i, j int) bool) {
sort.SliceStable(slice, less)
}
9 changes: 9 additions & 0 deletions gps/sort_pre_go_1_8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !go1.8

package gps

import "sort"

func sortSlice(slice interface{}, less func(i, j int) bool) {
sort.Slice(slice, less)
}

0 comments on commit 1baf6ee

Please # to comment.