From 9ea1a78bd4c57f0db465342f05496828a7784509 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 22 Feb 2020 21:17:39 +0100 Subject: [PATCH] FindUsedBlobs: Check for seen blobs before loading trees The only effective change in behavior is that that toplevel nodes can also be skipped. --- internal/restic/find.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/restic/find.go b/internal/restic/find.go index 09654f938..40ed2dac8 100644 --- a/internal/restic/find.go +++ b/internal/restic/find.go @@ -5,7 +5,11 @@ import "context" // FindUsedBlobs traverses the tree ID and adds all seen blobs (trees and data // blobs) to the set blobs. Already seen tree blobs will not be visited again. func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSet) error { - blobs.Insert(BlobHandle{ID: treeID, Type: TreeBlob}) + h := BlobHandle{ID: treeID, Type: TreeBlob} + if blobs.Has(h) { + return nil + } + blobs.Insert(h) tree, err := repo.LoadTree(ctx, treeID) if err != nil { @@ -19,13 +23,7 @@ func FindUsedBlobs(ctx context.Context, repo Repository, treeID ID, blobs BlobSe blobs.Insert(BlobHandle{ID: blob, Type: DataBlob}) } case "dir": - subtreeID := *node.Subtree - h := BlobHandle{ID: subtreeID, Type: TreeBlob} - if blobs.Has(h) { - continue - } - - err := FindUsedBlobs(ctx, repo, subtreeID, blobs) + err := FindUsedBlobs(ctx, repo, *node.Subtree, blobs) if err != nil { return err }