From 5d18f341c3191f7e472faa2659a9c973629a31a5 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Sun, 14 Jan 2018 03:31:07 +1100 Subject: [PATCH] restic: switch to pre-1.8 sort.Stable API This allows us to build restic with older Go versions. It's a bit odd they decided to implement things this way, given that the old sort.Interface code still exists in the repo... Signed-off-by: Aleksa Sarai --- cmd/restic/cmd_snapshots.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 5dfb45e9729e..9acf8c0a9d44 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -106,9 +106,7 @@ func newFilterLastSnapshotsKey(sn *restic.Snapshot) filterLastSnapshotsKey { // they will be joined and treated as one item. func FilterLastSnapshots(list restic.Snapshots) restic.Snapshots { // Sort the snapshots so that the newer ones are listed first - sort.SliceStable(list, func(i, j int) bool { - return list[i].Time.After(list[j].Time) - }) + sort.Stable(list) var results restic.Snapshots seen := make(map[filterLastSnapshotsKey]bool) @@ -124,11 +122,8 @@ func FilterLastSnapshots(list restic.Snapshots) restic.Snapshots { // PrintSnapshots prints a text table of the snapshots in list to stdout. func PrintSnapshots(stdout io.Writer, list restic.Snapshots, compact bool) { - - // always sort the snapshots so that the newer ones are listed last - sort.SliceStable(list, func(i, j int) bool { - return list[i].Time.Before(list[j].Time) - }) + // Always sort the snapshots so that the newer ones are listed last + sort.Stable(sort.Reverse(list)) // Determine the max widths for host and tag. maxHost, maxTag := 10, 6 -- 2.15.1