(ctx context.Context, sctx *super.Context, r sio.Reader, author, message, meta string)
| 48 | } |
| 49 | |
| 50 | func (b *Branch) Load(ctx context.Context, sctx *super.Context, r sio.Reader, author, message, meta string) (ksuid.KSUID, error) { |
| 51 | w, err := NewWriter(ctx, sctx, b.pool) |
| 52 | if err != nil { |
| 53 | return ksuid.Nil, err |
| 54 | } |
| 55 | err = sio.CopyWithContext(ctx, w, r) |
| 56 | if closeErr := w.Close(); err == nil { |
| 57 | err = closeErr |
| 58 | } |
| 59 | if err != nil { |
| 60 | return ksuid.Nil, err |
| 61 | } |
| 62 | objects := w.Objects() |
| 63 | if len(objects) == 0 { |
| 64 | return ksuid.Nil, commits.ErrEmptyTransaction |
| 65 | } |
| 66 | if message == "" { |
| 67 | message = loadMessage(objects) |
| 68 | } |
| 69 | appMeta, err := loadMeta(sctx, meta) |
| 70 | if err != nil { |
| 71 | return ksuid.Nil, err |
| 72 | } |
| 73 | // The load operation has only added new objects so we know its |
| 74 | // safe to merge at the tip and there can be no conflicts |
| 75 | // with other concurrent writers (except for updating the branch pointer |
| 76 | // which is handled by Branch.commit) |
| 77 | return b.commit(ctx, func(parent *branches.Config, retries int) (*commits.Object, error) { |
| 78 | return commits.NewAddsObject(parent.Commit, retries, author, message, appMeta, objects), nil |
| 79 | }) |
| 80 | } |
| 81 | |
| 82 | func loadMessage(objects []data.Object) string { |
| 83 | var b strings.Builder |
nothing calls this directly
no test coverage detected