From 41eaed003af5df8a01c66a016b0630262643b42e Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Sat, 15 Sep 2018 22:33:27 -0700 Subject: [PATCH] cli: added 'snapshot list --skip-identical option to shorten the output --- cli/command_snapshot_list.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cli/command_snapshot_list.go b/cli/command_snapshot_list.go index e878da87e..ef10bfd5a 100644 --- a/cli/command_snapshot_list.go +++ b/cli/command_snapshot_list.go @@ -5,6 +5,7 @@ "fmt" "path/filepath" "strings" + "time" "github.com/kopia/kopia/fs" "github.com/kopia/kopia/fs/repofs" @@ -26,6 +27,7 @@ snapshotListShowRetentionReasons = snapshotListCommand.Flag("retention", "Include retention reasons.").Default("true").Bool() snapshotListShowModTime = snapshotListCommand.Flag("mtime", "Include file mod time").Bool() shapshotListShowOwner = snapshotListCommand.Flag("owner", "Include owner").Bool() + snapshotListSkipIdentical = snapshotListCommand.Flag("skip-identical", "Skip identical snapshots").Bool() maxResultsPerPath = snapshotListCommand.Flag("max-results", "Maximum number of results.").Default("1000").Int() ) @@ -122,6 +124,20 @@ func outputManifestFromSingleSource(ctx context.Context, rep *repo.Repository, m manifests = manifests[len(manifests)-*maxResultsPerPath:] } + var previousOID object.ID + var elidedCount int + var maxElidedTime time.Time + + outputElided := func() { + if elidedCount > 0 { + fmt.Printf( + " + %v identical snapshots until %v\n\n", + elidedCount, + maxElidedTime.Format("2006-01-02 15:04:05 MST"), + ) + } + } + for _, m := range manifests { root, err := repofs.SnapshotRoot(rep, m) if err != nil { @@ -178,14 +194,26 @@ func outputManifestFromSingleSource(ctx context.Context, rep *repo.Repository, m if *snapshotListShowRetentionReasons { if len(m.RetentionReasons) > 0 { - bits = append(bits, "retention:"+strings.Join(m.RetentionReasons, ",")) + bits = append(bits, "("+strings.Join(m.RetentionReasons, ",")+")") } } + oid := ent.(object.HasObjectID).ObjectID() + if *snapshotListSkipIdentical && oid == previousOID { + elidedCount++ + maxElidedTime = m.StartTime + continue + } + + previousOID = oid + + outputElided() + elidedCount = 0 + fmt.Printf( " %v %v %v\n", m.StartTime.Format("2006-01-02 15:04:05 MST"), - ent.(object.HasObjectID).ObjectID(), + oid, strings.Join(bits, " "), ) @@ -194,6 +222,7 @@ func outputManifestFromSingleSource(ctx context.Context, rep *repo.Repository, m lastTotalFileSize = m.Stats.TotalFileSize } } + outputElided() return nil }