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

[WIP] Fall back to 'sort.Slice' on Go 1.7 where 'sort.SliceStable' does not exist #1968

Closed
wants to merge 1 commit into from
Closed
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
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
3 changes: 1 addition & 2 deletions gps/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package gps

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

Expand All @@ -21,7 +20,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
13 changes: 13 additions & 0 deletions gps/sort_go_1_8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build go1.8

package gps

import "sort"

func sortSlice(slice interface{}, less func(i, j int) bool) {
sort.SliceStable(slice, less)
}
13 changes: 13 additions & 0 deletions gps/sort_pre_go_1_8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !go1.8

package gps

import "sort"

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