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

Commit ca6ded9

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

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package gps
66

77
import (
88
"reflect"
9-
"sort"
109
"testing"
1110
)
1211

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

24-
sort.SliceStable(lps2, func(i, j int) bool {
23+
sortSlice(lps2, func(i, j int) bool {
2524
return lps2[i].Ident().Less(lps2[j].Ident())
2625
})
2726

gps/sort_go_1_8.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build go1.8
6+
7+
package gps
8+
9+
import "sort"
10+
11+
func sortSlice(slice interface{}, less func(i, j int) bool) {
12+
sort.SliceStable(slice, less)
13+
}

gps/sort_pre_go_1_8.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build !go1.8
6+
7+
package gps
8+
9+
import "sort"
10+
11+
func sortSlice(slice interface{}, less func(i, j int) bool) {
12+
sort.Slice(slice, less)
13+
}

0 commit comments

Comments
 (0)