From 6260f656daf3ce46fad16b1b6bc13238846dd4a0 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Wed, 12 Oct 2016 21:57:59 -0700 Subject: [PATCH] added sorting of 'kopia backups' output --- cmd/kopia/command_backups.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/kopia/command_backups.go b/cmd/kopia/command_backups.go index 0626042f7..24dd6a72e 100644 --- a/cmd/kopia/command_backups.go +++ b/cmd/kopia/command_backups.go @@ -4,6 +4,7 @@ "fmt" "log" "path/filepath" + "sort" "github.com/kopia/kopia/fs/repofs" "github.com/kopia/kopia/internal/units" @@ -86,7 +87,10 @@ func runBackupsCommand(context *kingpin.ParseContext) error { var lastSource repofs.SnapshotSourceInfo var count int - for _, m := range loadBackupManifests(conn.Vault, previous) { + manifests := loadBackupManifests(conn.Vault, previous) + sort.Sort(manifestSorter(manifests)) + + for _, m := range manifests { if m.Source != lastSource { fmt.Printf("\n%v\n", m.Source) lastSource = m.Source @@ -109,6 +113,22 @@ func runBackupsCommand(context *kingpin.ParseContext) error { return nil } +type manifestSorter []*repofs.Snapshot + +func (b manifestSorter) Len() int { return len(b) } +func (b manifestSorter) Less(i, j int) bool { + if b[i].Source.String() < b[j].Source.String() { + return true + } + if b[i].Source.String() > b[j].Source.String() { + return false + } + + return b[i].StartTime.UnixNano() < b[j].StartTime.UnixNano() +} + +func (b manifestSorter) Swap(i, j int) { b[i], b[j] = b[j], b[i] } + func deltaBytes(b int64) string { if b > 0 { return "(+" + units.BytesString(b) + ")"