(ctx context.Context, _ *db.Root, pool *db.Pool, branchName string, objectIDs []ksuid.KSUID, writeVectors bool, author, message, info string)
| 14 | ) |
| 15 | |
| 16 | func Compact(ctx context.Context, _ *db.Root, pool *db.Pool, branchName string, objectIDs []ksuid.KSUID, writeVectors bool, author, message, info string) (ksuid.KSUID, error) { |
| 17 | if len(objectIDs) < 2 { |
| 18 | return ksuid.Nil, errors.New("compact: two or more source objects required") |
| 19 | } |
| 20 | branch, err := pool.OpenBranchByName(ctx, branchName) |
| 21 | if err != nil { |
| 22 | return ksuid.Nil, err |
| 23 | } |
| 24 | base, err := pool.Snapshot(ctx, branch.Commit) |
| 25 | if err != nil { |
| 26 | return ksuid.Nil, err |
| 27 | } |
| 28 | compact := commits.NewSnapshot() |
| 29 | for _, oid := range objectIDs { |
| 30 | o, err := base.Lookup(oid) |
| 31 | if err != nil { |
| 32 | return ksuid.Nil, err |
| 33 | } |
| 34 | compact.AddDataObject(o) |
| 35 | } |
| 36 | sctx := super.NewContext() |
| 37 | lister := meta.NewSortedListerFromSnap(ctx, super.NewContext(), pool, compact, nil) |
| 38 | rctx := runtime.NewContext(ctx, sctx) |
| 39 | slicer := meta.NewSlicer(lister, sctx) |
| 40 | puller := meta.NewSequenceScanner(rctx, slicer, pool, nil, nil, nil) |
| 41 | w := db.NewSortedWriter(ctx, sctx, pool, writeVectors) |
| 42 | if err := sbuf.CopyPuller(w, puller); err != nil { |
| 43 | puller.Pull(true) |
| 44 | w.Abort() |
| 45 | return ksuid.Nil, err |
| 46 | } |
| 47 | if err := w.Close(); err != nil { |
| 48 | w.Abort() |
| 49 | return ksuid.Nil, err |
| 50 | } |
| 51 | commit, err := branch.CommitCompact(ctx, compact.SelectAll(), w.Objects(), w.Vectors(), author, message, info) |
| 52 | if err != nil { |
| 53 | w.Abort() |
| 54 | return ksuid.Nil, err |
| 55 | } |
| 56 | return commit, nil |
| 57 | } |
no test coverage detected