Skip to content

Commit

Permalink
fix(object): add support for raw leaves in object diff
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
  • Loading branch information
overbool committed Sep 15, 2018
1 parent 9962817 commit f7b14ba
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions dagutils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
}

var out []*Change
cleanA := a.Copy().(*dag.ProtoNode)
cleanB := b.Copy().(*dag.ProtoNode)
cleanA := a.Copy()
cleanB := b.Copy()

// strip out unchanged stuff
for _, lnk := range a.Links() {
Expand All @@ -132,17 +132,7 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
return nil, err
}

anodepb, ok := anode.(*dag.ProtoNode)
if !ok {
return nil, dag.ErrNotProtobuf
}

bnodepb, ok := bnode.(*dag.ProtoNode)
if !ok {
return nil, dag.ErrNotProtobuf
}

sub, err := Diff(ctx, ds, anodepb, bnodepb)
sub, err := Diff(ctx, ds, anode, bnode)
if err != nil {
return nil, err
}
Expand All @@ -152,8 +142,12 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
out = append(out, subc)
}
}
cleanA.RemoveNodeLink(l.Name)
cleanB.RemoveNodeLink(l.Name)
if cleanA, ok := cleanA.(*dag.ProtoNode); ok {
cleanA.RemoveNodeLink(l.Name)
}
if cleanB, ok := cleanB.(*dag.ProtoNode); ok{
cleanB.RemoveNodeLink(l.Name)
}
}
}

Expand Down

0 comments on commit f7b14ba

Please sign in to comment.