1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 16:26:11 +00:00

diff: list snapshots only once

This commit is contained in:
Michael Eischer 2021-11-07 21:26:05 +01:00
parent 5af828e3e6
commit 47243176fa

View file

@ -7,9 +7,9 @@ import (
"reflect" "reflect"
"sort" "sort"
"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -53,8 +53,8 @@ func init() {
f.BoolVar(&diffOptions.ShowMetadata, "metadata", false, "print changes in metadata") f.BoolVar(&diffOptions.ShowMetadata, "metadata", false, "print changes in metadata")
} }
func loadSnapshot(ctx context.Context, repo *repository.Repository, desc string) (*restic.Snapshot, error) { func loadSnapshot(ctx context.Context, be restic.Lister, repo restic.Repository, desc string) (*restic.Snapshot, error) {
id, err := restic.FindSnapshot(ctx, repo.Backend(), desc) id, err := restic.FindSnapshot(ctx, be, desc)
if err != nil { if err != nil {
return nil, errors.Fatal(err.Error()) return nil, errors.Fatal(err.Error())
} }
@ -342,12 +342,17 @@ func runDiff(opts DiffOptions, gopts GlobalOptions, args []string) error {
} }
} }
sn1, err := loadSnapshot(ctx, repo, args[0]) // cache snapshots listing
be, err := backend.MemorizeList(ctx, repo.Backend(), restic.SnapshotFile)
if err != nil {
return err
}
sn1, err := loadSnapshot(ctx, be, repo, args[0])
if err != nil { if err != nil {
return err return err
} }
sn2, err := loadSnapshot(ctx, repo, args[1]) sn2, err := loadSnapshot(ctx, be, repo, args[1])
if err != nil { if err != nil {
return err return err
} }