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

Commit 1baf6ee

Browse files
Fall back to 'sort.Slice' on Go 1.7 where 'sort.SliceStable' does not exist
1 parent 224a564 commit 1baf6ee

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

gps/constraint.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package gps
66

77
import (
88
"fmt"
9-
"sort"
109

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

378-
sort.SliceStable(out, func(i, j int) bool {
377+
sortSlice(out, func(i, j int) bool {
379378
return out[i].Ident.Less(out[j].Ident)
380379
})
381380
return

gps/lock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestLockedProjectSorting(t *testing.T) {
2121
lps2 := make([]LockedProject, len(lps))
2222
copy(lps2, lps)
2323

24-
sort.SliceStable(lps2, func(i, j int) bool {
24+
sortSlice(lps2, func(i, j int) bool {
2525
return lps2[i].Ident().Less(lps2[j].Ident())
2626
})
2727

gps/sort_go_1_8.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build go1.8
2+
3+
package gps
4+
5+
import "sort"
6+
7+
func sortSlice(slice interface{}, less func(i, j int) bool) {
8+
sort.SliceStable(slice, less)
9+
}

gps/sort_pre_go_1_8.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build !go1.8
2+
3+
package gps
4+
5+
import "sort"
6+
7+
func sortSlice(slice interface{}, less func(i, j int) bool) {
8+
sort.Slice(slice, less)
9+
}

0 commit comments

Comments
 (0)