From f58a44b911e52f85a4821dc18c9ef735afd67cc3 Mon Sep 17 00:00:00 2001 From: Chris Howie Date: Fri, 29 Mar 2019 20:23:24 -0400 Subject: [PATCH 1/2] Extend find --show-pack-id to work with --tree --- changelog/unreleased/issue-2229 | 6 ++++ cmd/restic/cmd_find.go | 51 +++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 changelog/unreleased/issue-2229 diff --git a/changelog/unreleased/issue-2229 b/changelog/unreleased/issue-2229 new file mode 100644 index 000000000..7c315be7b --- /dev/null +++ b/changelog/unreleased/issue-2229 @@ -0,0 +1,6 @@ +Enhancement: Extend "restic find --show-pack-id" to support --tree + +This makes it possible to find the pack containing a specific tree, which is +useful mostly in development. + +https://github.com/restic/restic/issues/2229 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 48b952f5d..06da75bc0 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -62,7 +62,7 @@ func init() { f.BoolVar(&findOptions.BlobID, "blob", false, "pattern is a blob-ID") f.BoolVar(&findOptions.TreeID, "tree", false, "pattern is a tree-ID") f.BoolVar(&findOptions.PackID, "pack", false, "pattern is a pack-ID") - f.BoolVar(&findOptions.ShowPackID, "show-pack-id", false, "display the pack-ID the blobs belong to (with --blob)") + f.BoolVar(&findOptions.ShowPackID, "show-pack-id", false, "display the pack-ID the blobs belong to (with --blob or --tree)") f.BoolVarP(&findOptions.CaseInsensitive, "ignore-case", "i", false, "ignore case for pattern") f.BoolVarP(&findOptions.ListLong, "long", "l", false, "use a long listing format showing size and mode") @@ -442,27 +442,36 @@ func (f *Finder) packsToBlobs(ctx context.Context, packs []string) error { return nil } -func (f *Finder) findBlobsPacks(ctx context.Context) { +func (f *Finder) findObjectPack(ctx context.Context, id string, t restic.BlobType) { idx := f.repo.Index() + + rid, err := restic.ParseID(id) + if err != nil { + Printf("Note: cannot find pack for object '%s', unable to parse ID: %v\n", id, err) + return + } + + blobs, found := idx.Lookup(rid, t) + if !found { + Printf("Object %s not found in the index\n", rid.Str()) + return + } + + for _, b := range blobs { + if b.ID.Equal(rid) { + Printf("Object belongs to pack %s\n ... Pack %s: %s\n", b.PackID, b.PackID.Str(), b.String()) + break + } + } +} + +func (f *Finder) findObjectsPacks(ctx context.Context) { for i := range f.blobIDs { - rid, err := restic.ParseID(i) - if err != nil { - Printf("Note: cannot find pack for blob '%s', unable to parse ID: %v\n", i, err) - continue - } + f.findObjectPack(ctx, i, restic.DataBlob) + } - blobs, found := idx.Lookup(rid, restic.DataBlob) - if !found { - Printf("Blob %s not found in the index\n", rid.Str()) - continue - } - - for _, b := range blobs { - if b.ID.Equal(rid) { - Printf("Blob belongs to pack %s\n ... Pack %s: %s\n", b.PackID, b.PackID.Str(), b.String()) - break - } - } + for i := range f.treeIDs { + f.findObjectPack(ctx, i, restic.TreeBlob) } } @@ -557,8 +566,8 @@ func runFind(opts FindOptions, gopts GlobalOptions, args []string) error { } f.out.Finish() - if opts.ShowPackID && f.blobIDs != nil { - f.findBlobsPacks(ctx) + if opts.ShowPackID && (f.blobIDs != nil || f.treeIDs != nil) { + f.findObjectsPacks(ctx) } return nil From 0cc3647e513d0ed1a6495d3f43e70b5d72df1c80 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 14 Apr 2019 19:29:12 +0200 Subject: [PATCH 2/2] Remove changelog entry, not relevant for end-users --- changelog/unreleased/issue-2229 | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 changelog/unreleased/issue-2229 diff --git a/changelog/unreleased/issue-2229 b/changelog/unreleased/issue-2229 deleted file mode 100644 index 7c315be7b..000000000 --- a/changelog/unreleased/issue-2229 +++ /dev/null @@ -1,6 +0,0 @@ -Enhancement: Extend "restic find --show-pack-id" to support --tree - -This makes it possible to find the pack containing a specific tree, which is -useful mostly in development. - -https://github.com/restic/restic/issues/2229