@cryptotaxi247 / kubo / commits / 26a3ebf00

fix(object): add support for raw leaves in object diff

License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>

Overbool committed Sep 16, 2018 at 01:03 UTC 26a3ebf00fc6bc3b9b92e1b145330d78ca9f7b01
1 file changed +9 -15
dagutils/diff.go
+9 -15
@@ -112,8 +112,8 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
112 }
113
114 var out []*Change
115 - cleanA := a.Copy().(*dag.ProtoNode)
116 - cleanB := b.Copy().(*dag.ProtoNode)
115 + cleanA := a.Copy()
116 + cleanB := b.Copy()
117
118 // strip out unchanged stuff
119 for _, lnk := range a.Links() {
@@ -132,17 +132,7 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
132 return nil, err
133 }
134
135 - anodepb, ok := anode.(*dag.ProtoNode)
136 - if !ok {
137 - return nil, dag.ErrNotProtobuf
138 - }
139 -
140 - bnodepb, ok := bnode.(*dag.ProtoNode)
141 - if !ok {
142 - return nil, dag.ErrNotProtobuf
143 - }
144 -
145 - sub, err := Diff(ctx, ds, anodepb, bnodepb)
135 + sub, err := Diff(ctx, ds, anode, bnode)
136 if err != nil {
137 return nil, err
138 }
@@ -152,8 +142,12 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
142 out = append(out, subc)
143 }
144 }
155 - cleanA.RemoveNodeLink(l.Name)
156 - cleanB.RemoveNodeLink(l.Name)
145 + if cleanA, ok := cleanA.(*dag.ProtoNode); ok {
146 + cleanA.RemoveNodeLink(l.Name)
147 + }
148 + if cleanB, ok := cleanB.(*dag.ProtoNode); ok {
149 + cleanB.RemoveNodeLink(l.Name)
150 + }
151 }
152 }
153