Skip to content

Commit

Permalink
polish(diff): allow options to be passed to LoadAMT when diffing (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist authored May 5, 2021
1 parent 2045095 commit dfbaa5c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (ch Change) String() string {
return string(b)
}

// Diff returns a set of changes that transform node 'a' into node 'b'.
func Diff(ctx context.Context, prevBs, curBs cbor.IpldStore, prev, cur cid.Cid) ([]*Change, error) {
prevAmt, err := LoadAMT(ctx, prevBs, prev)
// Diff returns a set of changes that transform node 'a' into node 'b'. opts are applied to both prev and cur.
func Diff(ctx context.Context, prevBs, curBs cbor.IpldStore, prev, cur cid.Cid, opts ...Option) ([]*Change, error) {
prevAmt, err := LoadAMT(ctx, prevBs, prev, opts...)
if err != nil {
return nil, xerrors.Errorf("loading previous root: %w", err)
}
Expand All @@ -51,11 +51,16 @@ func Diff(ctx context.Context, prevBs, curBs cbor.IpldStore, prev, cur cid.Cid)
height: prevAmt.height,
}

curAmt, err := LoadAMT(ctx, curBs, cur)
curAmt, err := LoadAMT(ctx, curBs, cur, opts...)
if err != nil {
return nil, xerrors.Errorf("loading current root: %w", err)
}

// TODO: remove when https://github.com/filecoin-project/go-amt-ipld/issues/54 is closed.
if curAmt.bitWidth != prevAmt.bitWidth {
return nil, xerrors.Errorf("diffing AMTs with differing bitWidths not supported (prev=%d, cur=%d)", prevAmt.bitWidth, curAmt.bitWidth)
}

curCtx := &nodeContext{
bs: curBs,
bitWidth: curAmt.bitWidth,
Expand Down

0 comments on commit dfbaa5c

Please sign in to comment.