Commit 868b4b06 authored by Jeromy's avatar Jeromy

basic implementation of object diff

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 70e5c88f
...@@ -75,17 +75,25 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha ...@@ -75,17 +75,25 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha
return e.Finalize(ds) return e.Finalize(ds)
} }
func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change { func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) ([]*Change, error) {
if len(a.Links) == 0 && len(b.Links) == 0 { if len(a.Links) == 0 && len(b.Links) == 0 {
ak, _ := a.Key() ak, err := a.Key()
bk, _ := b.Key() if err != nil {
return nil, err
}
bk, err := b.Key()
if err != nil {
return nil, err
}
return []*Change{ return []*Change{
&Change{ &Change{
Type: Mod, Type: Mod,
Before: ak, Before: ak,
After: bk, After: bk,
}, },
} }, nil
} }
var out []*Change var out []*Change
...@@ -99,9 +107,20 @@ func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change { ...@@ -99,9 +107,20 @@ func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change {
if bytes.Equal(l.Hash, lnk.Hash) { if bytes.Equal(l.Hash, lnk.Hash) {
// no change... ignore it // no change... ignore it
} else { } else {
anode, _ := lnk.GetNode(ctx, ds) anode, err := lnk.GetNode(ctx, ds)
bnode, _ := l.GetNode(ctx, ds) if err != nil {
sub := Diff(ctx, ds, anode, bnode) return nil, err
}
bnode, err := l.GetNode(ctx, ds)
if err != nil {
return nil, err
}
sub, err := Diff(ctx, ds, anode, bnode)
if err != nil {
return nil, err
}
for _, subc := range sub { for _, subc := range sub {
subc.Path = path.Join(lnk.Name, subc.Path) subc.Path = path.Join(lnk.Name, subc.Path)
...@@ -128,7 +147,7 @@ func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change { ...@@ -128,7 +147,7 @@ func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change {
}) })
} }
return out return out, nil
} }
type Conflict struct { type Conflict struct {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment